I have a textField (EditorTextField) where the user can input a search string. The textField is in turn part of a JPanel(GridBagLayout()), which is then used as the main component in a JBPopup.
I wanted to style a bit of the text in the field, and tried this:
textField.editor?.markupModel?.addRangeHighlighter(…)
However, textField.editor returns null. Is there some kind of initialization that might be missing, or how does one make the editor be available?
You can do some formatting on the EditorTextField like font and background, and you can call .addSettingsProvider() on it too.
The lambda variable is of type com.intellij.openapi.editor.ex.EditorEx, so you have access to an Editor instance, and you can configure things like this: textField.addSettingsProvider(provider -> provider.getSettings().setUseSoftWraps(true)).
See if any of the settings options are suitable for what you need.
Thank you for the tips, but this is not exactly what I’m after. What I want to do is style a portion of the text in the field, i.e. make a part of it red (to signal an error in part of the string). That’s why I want to get hold of the editor and add a range highlighter. But the trouble is that textField.editor returns null.
I was curious, so I did a bit of digging, but the only potential alternative I found is this:
if textField.document returns a non-null value, calling com.intellij.openapi.editor.EditorFactory.editors(textField.document) might return the desired Editor instance too.
Thank you, I appreciate the help. It doesn’t seem to work, however: textField.document is indeed non-null, but calling EditorFactory.getInstance().editors(textField.document) returns 0 editors, so no luck this way.