use of com.intellij.openapi.editor.ex.util.HighlighterIteratorWrapper in project intellij-community by JetBrains.
the class BraceHighlightingHandler method getLazyParsableHighlighterIfAny.
@NotNull
static EditorHighlighter getLazyParsableHighlighterIfAny(Project project, Editor editor, PsiFile psiFile) {
if (!PsiDocumentManager.getInstance(project).isCommitted(editor.getDocument())) {
return ((EditorEx) editor).getHighlighter();
}
PsiElement elementAt = psiFile.findElementAt(editor.getCaretModel().getOffset());
for (PsiElement e : SyntaxTraverser.psiApi().parents(elementAt).takeWhile(Conditions.notEqualTo(psiFile))) {
if (!(PsiUtilCore.getElementType(e) instanceof ILazyParseableElementType))
continue;
Language language = ILazyParseableElementType.LANGUAGE_KEY.get(e.getNode());
if (language == null)
continue;
TextRange range = e.getTextRange();
final int offset = range.getStartOffset();
SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, psiFile.getVirtualFile());
LexerEditorHighlighter highlighter = new LexerEditorHighlighter(syntaxHighlighter, editor.getColorsScheme()) {
@NotNull
@Override
public HighlighterIterator createIterator(int startOffset) {
return new HighlighterIteratorWrapper(super.createIterator(Math.max(startOffset - offset, 0))) {
@Override
public int getStart() {
return super.getStart() + offset;
}
@Override
public int getEnd() {
return super.getEnd() + offset;
}
};
}
};
highlighter.setText(editor.getDocument().getText(range));
return highlighter;
}
return ((EditorEx) editor).getHighlighter();
}
Aggregations