Action

Single space

Posted by dchar, Last update over 6 years ago

Remove blank lines from a selection or draft.

Steps

  • script

    // single space
    
    (() => {
    
      const getLines = () => {
        const e = editor;
        const t =
          e.getSelectedRange()[1] > 0 ?
          e.getTextInRange(...e.getSelectedLineRange()) :
          e.getText();
        return t.split('\n');
      };
    
      const setLines = (l) => {
        const t = l.join('\n') + '\n';
        const e = editor;
        if (e.getSelectedRange()[1] > 0) {
          const sel = e.getSelectedLineRange();
          e.setTextInRange(sel[0], sel[1], t);
          e.setSelectedRange(sel[0], t.length);
        } else {
          e.setText(t);
        }
      };
    
      const single = (l) => {
        return l.filter(l => l.trim());
      }
    
      setLines(single(getLines()));
    
    })();

Options

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