querkmachine/nova-randomize-everything

Text placement from contextual menu removes line feed

Closed this issue · 1 comments

When using Randomize Everything from the contextual-menu, the editor automatically selects (at a minimum) the line-feed of the current line. When the chosen random-text is placed, it replaces the line feed (which is unexpected because it brings the text of the following line up to the current line).

There might be a more elegant solution but: You could check editor.selectedText to see if the last character is "\n" and if it is add a line-feed to the placed text? e.g.,

function insertAtPosition(editor, cb) {
  var line_feed = ( editor.selectedText.slice(-1) === "\n" ) ? "\n" : "";
  
  editor.edit((textEditor) => {
    editor.selectedRanges.reverse().forEach((range) => {
      textEditor.replace(range, cb() + line_feed);
    });
  });
}

Hi @colinfoster, thanks for the bug report and the suggested changes.

I've incorporated a fix into Randomize Everything and have pushed an update to the Nova Extension Library. Thanks again!