highlighting a line in an openend file in Intellij project

I want to highlight a line of an opened file in an IntelliJ Project on a particular mouse action from ToolWindow .Given the linenumber . .Please help me with the necesary code snippets Intellij provides . or which Open API classes should I use to impelement this . I saw BackgroundEditorHighlighter in com.intellij.codeHighlighting . But i'm not able to do this with this .Anybody Please help me out.

2 comments
Comment actions Permalink

Assuming you have a reference to an Editor object named editor you can do something like the following (lineNumber is the zero-based logical line (vs visual line):

int startOffset = editor.getDocument.getLineStartOffset(lineNumber);
int endOffset = editor.getDocument.getLineEndOffset(lineNumber);
editor.getSelectionModel().setSelection(startOffset, endOffset);

If the caret is already on the line to be highlighted then it's even easier:

editor.getSelectionModel().selectLineAtCaret();

Rick

0
Comment actions Permalink

Thanks a lot Rick... The answer was the exact thing which I wanted .
Thanks once again

0

Please sign in to leave a comment.