Trying to replace COPY_HANDLER for an editor
Answered
I cannot find a way to supply a custom copy handler to an editor. The DataContext of the copy action always resolves to the EditorComponent and I can see no way to override. I am usually good at navigating mazes but cannt find a way to solve this. Please advise!
Please sign in to leave a comment.
Could you please give more details about what you're trying to achieve? Maybe registering CopyPastePostProcessor or CopyPastePreProcessor (namings are a bit obscure) can solve your problem.
I have a LanuageConsole and am trying to make it so when the user copies code from the history view the prompt doesn't get copied. CopyPastePreProcessor only gets invoked if the editor has an associated PsiFile, which is not the case here.
You can register an EditorActionHandler for "EditorCopy" action. In it you can detect whether it's invoked in your context and perform any required actions. If it's invoked in other context, you should delegate to the original handler (like com.intellij.codeInsight.editorActions.CopyHandler does).
This works! Thanks!
The only minor annoyance is that it puts a little bit of overhead on all editors.