Run code on paste?

Does anybody have a way to run some code on paste?

Specifically, I want to process any multi-line addition to the current document.

I don’t think there’s any event for that.

What I would do is make a new command called “Paste and process” or something like that, and it can grab the contents of the clipboard with nova.clipboard.readText(), process it, then insert it into the editor at the cursor position. Rather than overriding the existing paste function, have a separate one.

Another possibility would be to use the editor.onDidStopChanging() event to read the contents of the clipboard, search through the document back from the current selection position to see if it was pasted, and then replace it with the processed text. Could be horrible for performance though.

Good ideas! Cheers.

I’ll probably go with the first one if I revisit the extension (Reindent-o-matic)

As it is I just paste and press a hot key so it’s no big deal. Just would have been super-smooth to run automatically after pasting.