Action

Navigate Draft

Posted by @nahumck, Last update almost 6 years ago

Navigate around your Markdown-formatted draft by moving the cursor in the editor to the end of the heading (lines marked with 1-6 #’s). Also can move to the “Home” or “End” of the draft.

Steps

  • script

    // Find and Navigate to Headers
    // script by Tim Nahumck
    
    // Get the draft content
    var d = draft.content;
    var selRange = editor.getSelectedRange();
    
    //grab lines that start with # in any number
    var headers = d.match(/#+?\s.*/gi)
    
    //present lines in prompt
    var p = Prompt.create();
    p.title = "Choose Header";
    p.addButton("Home");
    for (i = 0; i < headers.length; i++) {
    	p.addButton(headers[i]);
    }
    p.addButton("End");
    var con = p.show();
    
    if (con) {
      if (p.buttonPressed == "Home") {
        editor.setSelectedRange(0,0);
      }
      else {
        if (p.buttonPressed == "End") {
          editor.setSelectedRange(d.length,0);
        }
        else {
          var header = p.buttonPressed;
          var position = d.search(header);
          editor.setSelectedRange(position+header.length,0)
        }
      }
      editor.focus();
    }
    else {
      context.cancel();
    }

Options

  • After Success Default
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.