Trigger action on word selection
已回答
Hi, I am a beginner at creating plugins. I want to know how to trigger an action when a word is selected. And is it impossible to know the selected word is code or annotation. Thanks.
请先登录再写评论。
You can listen for changes in selection/caret position.
See `com.intellij.openapi.editor.event.EditorEventMulticaster`
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000539524-how-to-register-a-universal-editor-onlick-listener
>to know the selected word is code or annotation
I'm not sure I understand the question, but these samples might help:
https://github.com/JetBrains/intellij-community/blob/master/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java#L1057
https://github.com/minman/browse-word-at-caret
You can also get notifications when 'EditorSelectWord' action is executed (see ActionManager.addAnActionListener), but that won't give you events on word selection using mouse double click. For the latter, EditorEventMulticaster mentioned above might help.