Trigger action on word selection

Answered

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.

0
2 comments

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

0

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.

0

Please sign in to leave a comment.