Dynamically change of caret color


Hello. I would like to develop a plugin that can dynamically change caret color based on language, for example: when English is enabled, then the caret is blue, if I switch to Russian, then it's red.

The question is: do you have an API for dynamically changing the caret color (you do, see comments), and how I can intercept a keyboard layout change (Russian/English) and change the color based on it. Is it even possible?


Comment actions Permalink

I got that for the caret change I should use something like this:

Caret caret = editor.getCaretModel().getPrimaryCaret();
caret.setVisualAttributes(new CaretVisualAttributes(JBColor.ORANGE, CaretVisualAttributes.Weight.NORMAL));

The question is: how can I detect keyboard layout change in the editor:

Case 1: in the editor, I can change the keyboard layout

Case 2: when switching between app I can change the keyboard layout and switch back to IDE, I should check the layout.

Comment actions Permalink

It seems it's not possible to obtain such information without using additional native integration with corresponding OS(es).

You can though switch color depending on actual pressed keys, so react after e.g. first russian character was typed.


Please sign in to leave a comment.