Drafts Action Directory

Expand template

Posted by yvonnezed, Last update 5 months ago

Designed to insert text and leave the cursor at the position indicated by ||

Don’t call this directly, create a script action defining a variable named template, and include this afterwards. E.g. const template =‘[||]’;

This will insert the brackets, leaving the cursor between them.

Install

Steps

  • script

    // Apply a template to selection, or insert the template if no selection, leaving the cursor indicated by ||
    
    const sel = editor.getSelectedText();
    const selRange = editor.getSelectedRange();
    const [start, end]=template.split('||');
    
    if (!sel || sel.length == 0) {
      editor.setSelectedText(start+end);
      editor.setSelectedRange(selRange[0]+start.length,0);
    }
    else {
      editor.setSelectedText(start+sel+end);
     editor.setSelectedRange(selRange[0]+selRange[1]+start.length+end.length,0);
    }
    

Options

  • After Success Default
    Notification Error
    Log Level Error

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.