use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project Perl5-IDEA by Camelcade.
the class PerlTypedHandler method beforeCharTyped.
@NotNull
@Override
public Result beforeCharTyped(char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull FileType fileType) {
CaretModel caretModel = editor.getCaretModel();
int currentOffset = caretModel.getOffset();
Document document = editor.getDocument();
CharSequence documentSequence = document.getCharsSequence();
if (currentOffset > documentSequence.length()) {
return Result.CONTINUE;
}
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(currentOffset);
IElementType nextTokenType = iterator.atEnd() ? null : iterator.getTokenType();
char nextChar = currentOffset == documentSequence.length() ? 0 : documentSequence.charAt(currentOffset);
if (c == '<' && nextTokenType == QUOTE_DOUBLE_CLOSE && nextChar == '>' && currentOffset > 0 && documentSequence.charAt(currentOffset - 1) == '<' && (currentOffset < 3 || PerlEditorUtil.getPreviousTokenType(highlighter.createIterator(currentOffset - 2)) != RESERVED_QQ)) {
document.replaceString(currentOffset, currentOffset + 1, "<");
caretModel.moveToOffset(currentOffset + 1);
return Result.STOP;
}
if (QUOTE_CLOSE_FIRST_ANY.contains(nextTokenType) && c == nextChar) {
caretModel.moveToOffset(currentOffset + 1);
return Result.STOP;
}
if (c == ':' && nextTokenType == PACKAGE && Perl5CodeInsightSettings.getInstance().AUTO_INSERT_COLON) {
document.insertString(currentOffset, "::");
caretModel.moveToOffset(currentOffset + 2);
AutoPopupController.getInstance(project).scheduleAutoPopup(editor);
return Result.STOP;
}
if (c == ' ') {
Result result = tryToAddFatComma(editor, file, currentOffset);
if (result != null) {
return result;
}
}
return Result.CONTINUE;
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project Perl5-IDEA by Camelcade.
the class TemplateToolkitPsiUtil method getLastOpenMarker.
@Nullable
@Contract("null -> null")
public static IElementType getLastOpenMarker(@Nullable Editor editor) {
if (editor == null) {
return null;
}
int offset = editor.getCaretModel().getOffset();
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
while (!iterator.atEnd()) {
IElementType tokenType = iterator.getTokenType();
if (TemplateToolkitSyntaxElements.OPEN_TAGS.contains(tokenType)) {
return tokenType;
}
iterator.retreat();
}
return null;
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-code-outline by sitano.
the class CodeOutlineImageEx method renderRestOfLineToImg.
/**
* Renders the characters at the given document offset to the code outline
* image until the first newline character is reached or until the right
* edge of the image is reached and no more characters can be rendered.
*
* @param startOff the offset into the document at which to start rendering
* @return how many characters were rendered, not including the newline
*/
@Override
protected int renderRestOfLineToImg(int startOff) {
final CharSequence chars = document.getCharsSequence();
final int endOff = document.getTextLength();
if (startOff >= endOff)
return 0;
final LogicalPosition startPos = editor.offsetToLogicalPosition(startOff);
final int line = startPos.line;
final EditorEx ex = (EditorEx) editor;
final EditorHighlighter hl = ex.getHighlighter();
final HighlighterIterator hi = hl.createIterator(startOff);
int col = startPos.column;
int painted = 0;
for (int i = startOff; i < endOff; i++) {
final char ch = chars.charAt(i);
while (!hi.atEnd() && i > hi.getEnd()) {
hi.advance();
}
if (ch == '\n')
break;
if (col >= visibleImgWidth)
break;
drawChar(ch, col, line, getCharColor(editor, hi));
painted++;
col++;
}
return painted;
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project idea-handlebars by dmarcotte.
the class HbEnterHandler method isBetweenHbTags.
/**
* Checks to see if {@code Enter} has been typed while the caret is between an open and close tag pair.
*
* @return true if between open and close tags, false otherwise
*/
private static boolean isBetweenHbTags(Editor editor, PsiFile file, int offset) {
if (offset == 0)
return false;
CharSequence chars = editor.getDocument().getCharsSequence();
if (chars.charAt(offset - 1) != '}')
return false;
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset - 1);
final PsiElement openerElement = file.findElementAt(iterator.getStart());
PsiElement openTag = HbPsiUtil.findParentOpenTagElement(openerElement);
if (openTag == null) {
return false;
}
iterator.advance();
if (iterator.atEnd()) {
// no more tokens, so certainly no close tag
return false;
}
final PsiElement closerElement = file.findElementAt(iterator.getStart());
PsiElement closeTag = HbPsiUtil.findParentCloseTagElement(closerElement);
// if we got this far, we're between open and close tags iff this is a close tag
return closeTag != null;
}
use of com.intellij.openapi.editor.highlighter.HighlighterIterator in project intellij-elixir by KronicDeth.
the class Issue443 method isLBraceTokenBrace.
/*
* Private Instance Methods
*/
private boolean isLBraceTokenBrace() {
int offset = myFixture.getCaretOffset();
Editor editor = myFixture.getEditor();
CharSequence text = editor.getDocument().getCharsSequence();
FileType fileType = ElixirFileType.INSTANCE;
HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(offset);
return BraceMatchingUtil.isLBraceToken(iterator, text, fileType);
}
Aggregations