use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class EnterInStringLiteralHandler method isInStringLiteral.
private static boolean isInStringLiteral(@NotNull Editor editor, @NotNull DataContext dataContext, int offset) {
Language language = EnterHandler.getLanguage(dataContext);
if (offset > 0 && language != null) {
QuoteHandler quoteHandler = TypedHandler.getLanguageQuoteHandler(language);
if (quoteHandler == null) {
FileType fileType = language.getAssociatedFileType();
quoteHandler = fileType != null ? TypedHandler.getQuoteHandlerForType(fileType) : null;
}
if (quoteHandler != null) {
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
return StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType()) || quoteHandler.isInsideLiteral(iterator);
}
}
return false;
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class BraceHighlightingHandler method doHighlight.
private void doHighlight(int offset, int originalOffset, @NotNull FileType fileType) {
if (myEditor.getFoldingModel().isOffsetCollapsed(offset))
return;
HighlighterIterator iterator = getEditorHighlighter().createIterator(offset);
final CharSequence chars = myDocument.getCharsSequence();
if (BraceMatchingUtil.isLBraceToken(iterator, chars, fileType)) {
IElementType tokenType = iterator.getTokenType();
iterator.advance();
if (!iterator.atEnd() && BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) {
if (BraceMatchingUtil.isPairBraces(tokenType, iterator.getTokenType(), fileType) && originalOffset == iterator.getStart())
return;
}
iterator.retreat();
highlightLeftBrace(iterator, false, fileType);
if (offset > 0) {
iterator = getEditorHighlighter().createIterator(offset - 1);
if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) {
highlightRightBrace(iterator, fileType);
}
}
} else if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType)) {
highlightRightBrace(iterator, fileType);
}
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class BraceHighlightingHandler method highlightScope.
private void highlightScope(int offset, @NotNull FileType fileType) {
if (myEditor.getFoldingModel().isOffsetCollapsed(offset))
return;
if (myEditor.getDocument().getTextLength() <= offset)
return;
HighlighterIterator iterator = getEditorHighlighter().createIterator(offset);
final CharSequence chars = myDocument.getCharsSequence();
if (!BraceMatchingUtil.isStructuralBraceToken(fileType, iterator, chars)) {
// if (BraceMatchingUtil.isRBraceTokenToHighlight(myFileType, iterator) || BraceMatchingUtil.isLBraceTokenToHighlight(myFileType, iterator)) return;
} else {
if (BraceMatchingUtil.isRBraceToken(iterator, chars, fileType) || BraceMatchingUtil.isLBraceToken(iterator, chars, fileType))
return;
}
if (!BraceMatchingUtil.findStructuralLeftBrace(fileType, iterator, chars)) {
removeLineMarkers();
return;
}
highlightLeftBrace(iterator, true, fileType);
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class CustomFileTypeFoldingBuilder method buildBraceMatcherBasedFolding.
public static void buildBraceMatcherBasedFolding(List<FoldingDescriptor> descriptors, PsiElement root, Document document, SyntaxHighlighter highlighter) {
LexerEditorHighlighter editorHighlighter = new LexerEditorHighlighter(highlighter, EditorColorsManager.getInstance().getGlobalScheme());
editorHighlighter.setText(document.getText());
FileType fileType = root.getContainingFile().getFileType();
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, root.getLanguage());
TextRange totalRange = root.getTextRange();
final HighlighterIterator iterator = editorHighlighter.createIterator(totalRange.getStartOffset());
final LinkedList<Trinity<Integer, Integer, IElementType>> stack = new LinkedList<>();
String editorText = document.getText();
while (!iterator.atEnd() && iterator.getStart() < totalRange.getEndOffset()) {
final Trinity<Integer, Integer, IElementType> last;
if (braceMatcher.isLBraceToken(iterator, editorText, fileType) && braceMatcher.isStructuralBrace(iterator, editorText, fileType)) {
stack.addLast(Trinity.create(iterator.getStart(), iterator.getEnd(), iterator.getTokenType()));
} else if (braceMatcher.isRBraceToken(iterator, editorText, fileType) && braceMatcher.isStructuralBrace(iterator, editorText, fileType) && !stack.isEmpty() && braceMatcher.isPairBraces((last = stack.getLast()).third, iterator.getTokenType())) {
stack.removeLast();
TextRange range = new TextRange(last.first, iterator.getEnd());
if (StringUtil.countChars(document.getText(range), '\n') >= 3) {
descriptors.add(new FoldingDescriptor(root, range));
}
}
iterator.advance();
}
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-community by JetBrains.
the class CustomFileTypeSelectWordHandler method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
List<TextRange> superResult = super.select(e, editorText, cursorOffset, editor);
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(cursorOffset);
if (CustomFileTypeQuoteHandler.isQuotedToken(iterator.getTokenType())) {
List<TextRange> result = ContainerUtil.newArrayList();
int start = iterator.getStart();
int end = iterator.getEnd();
if (end - start > 2) {
result.add(new TextRange(start + 1, end - 1));
}
result.add(new TextRange(start, end));
if (superResult != null) {
result.addAll(superResult);
}
return result;
}
return superResult;
}
Aggregations