use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class CodeBlockUtil method calcBlockStartOffset.
private static int calcBlockStartOffset(Editor editor, PsiFile file) {
int offset = editor.getCaretModel().getOffset() - 1;
if (offset < 0)
return -1;
Document document = editor.getDocument();
final FileType fileType = file.getFileType();
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
int depth = 0;
Language braceType;
boolean isAfterRBrace = false;
if (isRStructuralBrace(fileType, iterator, document.getCharsSequence())) {
isAfterRBrace = true;
depth = -1;
braceType = getBraceType(iterator);
} else {
braceType = null;
}
boolean moved = false;
while (true) {
if (iterator.atEnd())
return -1;
if (isLStructuralBrace(fileType, iterator, document.getCharsSequence()) && (braceType == getBraceType(iterator) || braceType == null)) {
if (braceType == null) {
braceType = getBraceType(iterator);
}
if (moved) {
if (depth == 0)
break;
depth--;
}
} else if (isRStructuralBrace(fileType, iterator, document.getCharsSequence()) && (braceType == getBraceType(iterator) || braceType == null)) {
if (braceType == null) {
braceType = getBraceType(iterator);
}
depth++;
}
moved = true;
iterator.retreat();
}
return isAfterRBrace ? iterator.getStart() : iterator.getEnd();
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class GStringBackspaceHandlerDelegate method beforeCharDeleted.
@Override
public void beforeCharDeleted(char c, PsiFile file, Editor editor) {
if (c != '{')
return;
if (!(file instanceof GroovyFile))
return;
final int offset = editor.getCaretModel().getOffset();
final EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
if (offset < 1)
return;
HighlighterIterator iterator = highlighter.createIterator(offset);
if (iterator.getTokenType() != GroovyTokenTypes.mRCURLY)
return;
iterator.retreat();
if (iterator.getStart() < 1 || iterator.getTokenType() != GroovyTokenTypes.mLCURLY)
return;
editor.getDocument().deleteString(offset, offset + 1);
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class SyntaxHighlighterOverEditorHighlighter method resetPosition.
public void resetPosition(int startOffset) {
if (lexer instanceof LexerEditorHighlighterLexer) {
((LexerEditorHighlighterLexer) lexer).resetPosition(startOffset);
HighlighterIterator iterator = ((LexerEditorHighlighterLexer) lexer).getHighlighterIterator();
if (iterator instanceof LayeredHighlighterIterator) {
layeredHighlighterIterator = (LayeredHighlighterIterator) iterator;
} else {
layeredHighlighterIterator = null;
}
} else {
CharSequence text = lexer.getBufferSequence();
lexer.start(text, startOffset, text.length());
}
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class EditorPainter method paintBorderEffect.
private void paintBorderEffect(Graphics2D g, ClipDetector clipDetector, EditorHighlighter highlighter, int clipStartOffset, int clipEndOffset) {
HighlighterIterator it = highlighter.createIterator(clipStartOffset);
while (!it.atEnd() && it.getStart() < clipEndOffset) {
TextAttributes attributes = it.getTextAttributes();
if (isBorder(attributes)) {
paintBorderEffect(g, clipDetector, it.getStart(), it.getEnd(), attributes);
}
it.advance();
}
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class LineLayout method createRuns.
private static List<BidiRun> createRuns(EditorView view, char[] text, int startOffsetInEditor) {
int textLength = text.length;
if (view.getEditor().myDisableRtl || !Bidi.requiresBidi(text, 0, textLength)) {
return Collections.singletonList(new BidiRun(textLength));
}
List<BidiRun> runs = new ArrayList<>();
int flags = view.getBidiFlags();
if (startOffsetInEditor >= 0) {
// running bidi algorithm separately for text fragments corresponding to different lexer tokens
int relLastOffset = 0;
IElementType lastToken = null;
HighlighterIterator iterator = view.getEditor().getHighlighter().createIterator(startOffsetInEditor);
while (!iterator.atEnd() && (iterator.getStart() - startOffsetInEditor) < textLength) {
int iteratorRelStart = alignToCodePointBoundary(text, iterator.getStart() - startOffsetInEditor);
int iteratorRelEnd = alignToCodePointBoundary(text, iterator.getEnd() - startOffsetInEditor);
IElementType currentToken = iterator.getTokenType();
int relStartOffset = Math.max(0, iteratorRelStart);
String lcPrefix = getLineCommentPrefix(currentToken);
// for line comments we process prefix and following text separately
if (!StringUtil.isEmpty(lcPrefix) && lcPrefix.length() <= (iteratorRelEnd - iteratorRelStart) && CharArrayUtil.regionMatches(text, relStartOffset, relStartOffset + lcPrefix.length(), lcPrefix) && !isInsideSurrogatePair(text, relStartOffset + lcPrefix.length())) {
addRuns(runs, text, relLastOffset, relStartOffset, flags);
int textStartOffset = Math.min(textLength, Math.min(iteratorRelEnd, CharArrayUtil.shiftForward(text, relStartOffset + lcPrefix.length(), " \t")));
relLastOffset = Math.min(iteratorRelEnd, textLength);
lastToken = null;
addRuns(runs, text, relStartOffset, textStartOffset, flags);
addRuns(runs, text, textStartOffset, relLastOffset, flags);
} else if (distinctTokens(lastToken, currentToken)) {
addRuns(runs, text, relLastOffset, relStartOffset, flags);
lastToken = currentToken;
relLastOffset = relStartOffset;
}
iterator.advance();
}
addRuns(runs, text, relLastOffset, textLength, flags);
} else {
addRuns(runs, text, 0, textLength, flags);
}
for (BidiRun run : runs) {
assert !isInsideSurrogatePair(text, run.startOffset);
assert !isInsideSurrogatePair(text, run.endOffset);
}
return runs;
}
Aggregations