biati-digital / nova-text-tools

Swiss Army knife for text manipulation and selection Sort, Transform, Filter, Delete Duplicates, Encode, Decode and much more...
16 stars 2 forks source link

Suggestion: Kill Lines #26

Open csuhta opened 7 months ago

csuhta commented 7 months ago

I made a tiny plugin to handle this for myself, but it would be something that would fit inside this project and probably be implemented better:

I use ⌘E to kill the current line. Wherever my cursor is, the entire line is deleted. If I have a selection that spans multiple lines, they're all deleted.

Most importantly, this command does not need you to highlight exactly the whole line or entire text you want to be deleted, just wherever your cursor is, whatever you have highlighted, or wherever your multiple cursors are, each line involved is deleted

This is what I did, there is probably a better way to do it:

nova.commands.register("example.delete-lines", (editor) => {
  editor.selectLinesContainingCursors();
  editor.edit((actionQueue) => {
    // When multiple cursors are involved, ranges must be deleted bottom-up
    // so it can be performed as one atomic commit
    editor.selectedRanges.reverse().forEach((range) => {
      actionQueue.delete(range);
    });
  });
});
biati-digital commented 6 months ago

Hi, thank's for the suggestion. I'll make some tests with the code you shared. 👍