how to listen to editor copy/paste event?

Answered

I want to execute some codes after some text pasted into eidtor, what should i do? Is there any listener or event support this? 

0
5 comments

I had tried com.intellij.copyPastePostProcessor,but it's strange that that event only triggered when i copy or cut text from editor, but not triggered when i paste text into editor.

0

Paste Pre and Post Processors are only invoked on copy/cut to massage the transferable data.

You need to implement the editor action handler extension point `<editorActionHandler action="EditorPaste" implementationClass="yourImplementation" />`, and defer to original action handler, passed to the constructor of your class, if you do not need to do anything for the current paste action.

I don't know if it was fixed but any exceptions caused by original handlers, to which you deferred, will cause the exception to be logged as caused by your plugin. So if you don't care about the order of your handler add `order="last"` attribute to your extension point registration. It will save you a lot of headaches.

 

1

Got it, thank you very much.

0

BTW, what I said about Pre/Post processors was not quite accurate. Preprocessor has on copy and on paste preprocess methods. On paste you can change the text pasted in the preprocessOnPaste() method. In the post processor you can do more with the transferable and the pasted text, after the paste.

In all cases the PRE/POST processors deal with TEXT clipboard content. EditorPasteHandler lets you handle any transferable content.

If you are only dealing with TEXT, you should be able to handle what you need with just pre/post processors. However, the editor paste handler is more straight forward to implement since it is not abstracted by the IDE.

0

Please sign in to leave a comment.