Invocation of 'paste' operation for specific caret is not supported

Answered

Hi there,

users and I have noticed the following exception https://github.com/holgerbrandl/pasteimages/issues/19:

java.lang.AssertionError: Invocation of 'paste' operation for specific caret is not supported
at com.intellij.codeInsight.editorActions.PasteHandler.doExecute(PasteHandler.java:54)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:219)
at com.systema.eia.misc.PasteLinkHandler.doExecute(PasteLinkHandler.java:88)
at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:219)
at img2md.PasteImageHandler.doExecute(PasteImageHandler.java:87)
at img2md.PasteImageHandler.execute(PasteImageHandler.java:63)
at com.intellij.openapi.editor.impl.EditorImpl.lambda$handleDrop$17(EditorImpl.java:4537)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
at com.intellij.openapi.editor.impl.EditorImpl.handleDrop(EditorImpl.java:4517)

Essentially what I'm doing is

@Override
public void execute(Editor editor, DataContext dataContext, Producer<Transferable> producer) {
Caret caret = editor.getCaretModel().getPrimaryCaret();
doExecute(editor, caret, dataContext);
}

and in doExecute:

 myOriginalHandler.execute(editor, caret, dataContext);

The myOriginalHandler is passed as a constructor parameter

It's not much code in total anyway, which you can find at https://github.com/holgerbrandl/pasteimages/blob/233b004b01f601fb9d74b67e3638a8b22aaa269e/src/img2md/PasteImageHandler.java#L87

Do you have an idea what could cause the exception, and how to address it in my plugin's implementation?

Thanks in advance,

best regards,

Holger

3 comments
Comment actions Permalink

doExecute can be called with null meaning perform for all carets in the editor or can be called for individual carets of the editor (multi-caret mode).

Some action handlers do not support operations for specific carets since they handle all carets themselves. Using getCurrentCaret() should take care of it.

Short story, try using editor.getCaretModel().getCurrentCaret() instead of getPrimaryCaret(). This will be null if there is no current caret (ie. not in caretModel().runForEachCaret()) I think null could be used instead but I am not sure of this for all cases of paste handler.

 

0
Comment actions Permalink

`editor.getCaretModel().getCurrentCaret()` will never return `null` (if there's no `runForEachCaret()` call, the primary one will be returned).

Just pass `null` as `caret` to `myOriginalHandler.execute(editor, caret, dataContext);` call.

0
Comment actions Permalink

Thanks for your help. I've updated the plugin accordingly.

Best

0

Please sign in to leave a comment.