Action

Draft Modifier…

Posted by @nahumck, Last update over 6 years ago

This is a single action that contains the following actions:
• Remove Blank Lines
• Remove Duplicate Lines
• Split Draft at Cursor

Steps

  • script

    //Draft Modifier Key
    
    var p = Prompt.create();
    p.title = "Select Command";
    p.addButton("Remove Blank Lines");
    p.addButton("Remove Duplicate Lines");
    p.addButton("Split Draft at Cursor");
    
    var con = p.show();
    
    if (con) {
      //Remove Blank Lines from draft
      if (p.buttonPressed == "Remove Blank Lines") {
        draft.content = draft.content.replace(/$\s*\n+/gm, "\n");
        draft.update();
      }
    
      // Remove dulicate lines from draft
      if (p.buttonPressed == "Remove Duplicate Lines") {
        var lines = draft.content.split("\n");
        var newLines = [];
        for (var ix=0; ix<lines.length; ix++) {
          var line = lines[ix];
          if (newLines.indexOf(line) == -1) { 
            newLines.push(line);
          }
        }
        draft.content = newLines.join("\n");
        draft.update();
      }
    
      //Split Draft at Cursor
      if (p.buttonPressed == "Split Draft at Cursor") {
        var before = draft.content.substring(0, draft.selectionStart);
        var after = draft.content.substring(draft.selectionStart);
        if(before.length == 0 || after.length == 0) {
          stopAction();
        }
        //update current draft with text before cursor
        draft.content = before;
        draft.update();
        //create new draft with text after cursor
        var d = Draft.create();
        d.content = after;
        d.update();	
      }
    }
    else {
      context.cancel("cancelled by user");
    }

Options

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