I know how to highlight a PsiElement, But how to do it for one line? I want highlight java source code in my plugin like the test coverage do.
Asked
Active
Viewed 475 times
1 Answers
1
Use these code in the UI thread, can accomplish the goal.
int lineNum = document.getLineNumber(needHighlightPsiElement.getTextRange().getStartOffset());
final TextAttributes textattributes = new TextAttributes(null, backgroundColor, null, EffectType.LINE_UNDERSCORE, Font.PLAIN);
final Project project = needHighlightPsiElement.getProject();
final FileEditorManager editorManager = FileEditorManager.getInstance(project);
final Editor editor = editorManager.getSelectedTextEditor();
editor.getMarkupModel().addLineHighlighter(lineNum, HighlighterLayer.CARET_ROW, textattributes);

yanyu
- 219
- 2
- 11