Detect on Paste event?

Hi all,

I'm working on my AsciiDoc plugin, and I'd like to add an 'on paste' feature to detect if the clipboard contains either markdown or HTML, and convert it to adoc if possible. How can I listen to this, and do I need to register a component somewhere? Any hints welcome!




You can use the CopyPastePostProcessor extension point to achieve this. (This will work when copy/pasting from one IntelliJ IDEA editor to another. When copying from an external application, it's generally impossible to detect whether the clipboard contains markdown.)


Hi Dmitry,

Thanks for the info. Why would that be impossible? I understand IntelliJ doesn't have access when I copy something from a different application, but the moment before I paste, I could technically intercept what is being pasted right? I think the Scala plugin does a similar thing, now that I think of it...


The Scala plugin also does that when you copy code from a Java file in IntelliJ IDEA.

You can intercept what's being pasted, but you cannot detect whether it's markdown or asciidoc, because any text is both valid markdown and valid asciidoc.


True, but what I wanted to do was based on the context guess if it's HTML (that should be doable) or Markdown (which is a bit more tricky, but I could check if it has titles starting with #-es), and if it's one of those, convert it AsciiDoc.