Drafts Action Directory

Navigate Draft

Posted by @nahumck, Last updated: 2018-05-27 09:33:59 UTC

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.

Install

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();
    }
Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.