use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-plugins by JetBrains.
the class ActionScriptHighlightingTest method testScriptHighlightingInE4X.
public void testScriptHighlightingInE4X() throws Exception {
// 10 20 30 40 50
// 01234567890123456789012 34567890123456 7 89012 34567890123456789
String text = "var a = <xml>{ c }</xml>";
configureByFile(BASE_PATH + getTestName(false) + ".js2");
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(myProject, getFile().getVirtualFile());
highlighter.setText(text);
HighlighterIterator iterator = highlighter.createIterator(15);
assertEquals(JSTokenTypes.IDENTIFIER, iterator.getTokenType());
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project Perl5-IDEA by Camelcade.
the class PerlEnterInBracketsHandler method preprocessEnter.
@Override
public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) {
if (!file.getLanguage().is(PerlLanguage.INSTANCE) || !CodeInsightSettings.getInstance().SMART_INDENT_ON_ENTER) {
return Result.Continue;
}
Integer currentOffset = caretOffset.get();
if (currentOffset < 1) {
return Result.Continue;
}
assert editor instanceof EditorEx;
EditorHighlighter editorHighlighter = ((EditorEx) editor).getHighlighter();
Document document = editor.getDocument();
CharSequence documentChars = document.getCharsSequence();
HighlighterIterator highlighterIterator = editorHighlighter.createIterator(currentOffset - 1);
IElementType previousTokenType = PerlEditorUtil.getPreviousTokenType(highlighterIterator);
if (highlighterIterator.atEnd() || StringUtil.containsLineBreak(documentChars.subSequence(highlighterIterator.getStart(), currentOffset))) {
return Result.Continue;
}
int openTokenStart = highlighterIterator.getStart();
IElementType nextTokenType = PerlEditorUtil.getNextTokenType(highlighterIterator);
if (highlighterIterator.atEnd() || StringUtil.containsLineBreak(documentChars.subSequence(currentOffset, highlighterIterator.getEnd()))) {
return Result.Continue;
}
if (previousTokenType == LEFT_BRACKET && nextTokenType == RIGHT_BRACKET) {
doIndent(file, editor, dataContext, originalHandler, document);
} else if (previousTokenType == QUOTE_SINGLE_OPEN && nextTokenType == QUOTE_SINGLE_CLOSE && openTokenStart > 0) {
IElementType qwTokenType = PerlEditorUtil.getPreviousTokenType(editorHighlighter.createIterator(openTokenStart - 1));
if (qwTokenType == RESERVED_QW) {
doIndent(file, editor, dataContext, originalHandler, document);
}
}
return Result.Continue;
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter 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.EditorHighlighter 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.EditorHighlighter 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;
}
Aggregations