use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-plugins by JetBrains.
the class CfmlEnterHandler method isBetweenCfmlTags.
private static boolean isBetweenCfmlTags(PsiFile file, Editor editor, 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);
if (iterator.getTokenType() != CfmlTokenTypes.R_ANGLEBRACKET)
return false;
iterator.retreat();
int retrieveCount = 1;
while (!iterator.atEnd()) {
final IElementType tokenType = iterator.getTokenType();
if (tokenType == CfmlTokenTypes.LSLASH_ANGLEBRACKET)
return false;
if (tokenType == CfmlTokenTypes.OPENER)
break;
++retrieveCount;
iterator.retreat();
}
for (int i = 0; i < retrieveCount; ++i) iterator.advance();
iterator.advance();
return !iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.LSLASH_ANGLEBRACKET;
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-plugins by JetBrains.
the class CfmlMatcherTest method doTest.
private void doTest() throws Throwable {
final int pairOffset = configureByTestFile(getTestName(false));
int offset = myFixture.getEditor().getCaretModel().getOffset();
EditorHighlighter editorHighlighter = ((EditorEx) myFixture.getEditor()).getHighlighter();
HighlighterIterator iterator = editorHighlighter.createIterator(offset);
boolean forward = offset < pairOffset;
boolean matched = BraceMatchingUtil.matchBrace(myFixture.getEditor().getDocument().getCharsSequence(), myFixture.getFile().getFileType(), iterator, forward);
assertTrue(matched);
assertEquals(pairOffset, iterator.getStart());
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class TodoTreeBuilder method validateCache.
private void validateCache() {
TodoTreeStructure treeStructure = getTodoTreeStructure();
// First of all we need to update "dirty" file set.
for (Iterator<VirtualFile> i = myDirtyFileSet.iterator(); i.hasNext(); ) {
VirtualFile file = i.next();
PsiFile psiFile = file.isValid() ? PsiManager.getInstance(myProject).findFile(file) : null;
if (psiFile == null || !treeStructure.accept(psiFile)) {
if (myFileTree.contains(file)) {
myFileTree.removeFile(file);
if (myFile2Highlighter.containsKey(file)) {
// highlighter isn't needed any more
myFile2Highlighter.remove(file);
}
}
} else {
// file is valid and contains T.O.D.O items
myFileTree.removeFile(file);
// file can be moved. remove/add calls move it to another place
myFileTree.add(file);
if (myFile2Highlighter.containsKey(file)) {
// update highlighter text
Document document = PsiDocumentManager.getInstance(myProject).getDocument(psiFile);
EditorHighlighter highlighter = myFile2Highlighter.get(file);
highlighter.setText(document.getCharsSequence());
}
}
i.remove();
}
LOG.assertTrue(myDirtyFileSet.isEmpty());
// Now myDirtyFileSet should be empty
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class TextWithMarkupProcessor method collectTransferableData.
@NotNull
@Override
public List<RawTextWithMarkup> collectTransferableData(PsiFile file, Editor editor, int[] startOffsets, int[] endOffsets) {
if (!RichCopySettings.getInstance().isEnabled()) {
return Collections.emptyList();
}
try {
RichCopySettings settings = RichCopySettings.getInstance();
List<Caret> carets = editor.getCaretModel().getAllCarets();
Caret firstCaret = carets.get(0);
final int indentSymbolsToStrip;
final int firstLineStartOffset;
if (Registry.is("editor.richcopy.strip.indents") && carets.size() == 1) {
Pair<Integer, Integer> p = calcIndentSymbolsToStrip(editor.getDocument(), firstCaret.getSelectionStart(), firstCaret.getSelectionEnd());
firstLineStartOffset = p.first;
indentSymbolsToStrip = p.second;
} else {
firstLineStartOffset = firstCaret.getSelectionStart();
indentSymbolsToStrip = 0;
}
logInitial(editor, startOffsets, endOffsets, indentSymbolsToStrip, firstLineStartOffset);
CharSequence text = editor.getDocument().getCharsSequence();
EditorColorsScheme schemeToUse = settings.getColorsScheme(editor.getColorsScheme());
EditorHighlighter highlighter = HighlighterFactory.createHighlighter(file.getViewProvider().getVirtualFile(), schemeToUse, file.getProject());
highlighter.setText(text);
MarkupModel markupModel = DocumentMarkupModel.forDocument(editor.getDocument(), file.getProject(), false);
Context context = new Context(text, schemeToUse, indentSymbolsToStrip);
int endOffset = 0;
Caret prevCaret = null;
for (Caret caret : carets) {
int caretSelectionStart = caret.getSelectionStart();
int caretSelectionEnd = caret.getSelectionEnd();
int startOffsetToUse;
int additionalShift = 0;
if (caret == firstCaret) {
startOffsetToUse = firstLineStartOffset;
} else {
startOffsetToUse = caretSelectionStart;
assert prevCaret != null;
String prevCaretSelectedText = prevCaret.getSelectedText();
// Block selection fills short lines by white spaces
int fillStringLength = prevCaretSelectedText == null ? 0 : prevCaretSelectedText.length() - (prevCaret.getSelectionEnd() - prevCaret.getSelectionStart());
context.addCharacter(endOffset + fillStringLength);
additionalShift = fillStringLength + 1;
}
context.reset(endOffset - caretSelectionStart + additionalShift);
endOffset = caretSelectionEnd;
prevCaret = caret;
if (endOffset <= startOffsetToUse) {
continue;
}
MyMarkupIterator markupIterator = new MyMarkupIterator(text, new CompositeRangeIterator(schemeToUse, new HighlighterRangeIterator(highlighter, startOffsetToUse, endOffset), new MarkupModelRangeIterator(markupModel, schemeToUse, startOffsetToUse, endOffset)), schemeToUse);
try {
context.iterate(markupIterator, endOffset);
} finally {
markupIterator.dispose();
}
}
SyntaxInfo syntaxInfo = context.finish();
logSyntaxInfo(syntaxInfo);
createResult(syntaxInfo, editor);
return ObjectUtils.notNull(myResult, Collections.<RawTextWithMarkup>emptyList());
} catch (Exception e) {
// catching the exception so that the rest of copy/paste functionality can still work fine
LOG.error(e);
}
return Collections.emptyList();
}
use of com.intellij.openapi.editor.highlighter.EditorHighlighter in project intellij-community by JetBrains.
the class PsiViewerDialog method updateEditor.
private void updateEditor() {
final Object source = getSource();
final String fileName = "Dummy." + (source instanceof FileType ? ((FileType) source).getDefaultExtension() : "txt");
final LightVirtualFile lightFile;
if (source instanceof PsiViewerExtension) {
lightFile = new LightVirtualFile(fileName, ((PsiViewerExtension) source).getDefaultFileType(), "");
} else if (source instanceof LanguageFileType) {
lightFile = new LightVirtualFile(fileName, ObjectUtils.chooseNotNull((Language) myDialectComboBox.getSelectedItem(), ((LanguageFileType) source).getLanguage()), "");
} else if (source instanceof FileType) {
lightFile = new LightVirtualFile(fileName, (FileType) source, "");
} else {
return;
}
EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, lightFile);
try {
myEditor.setHighlighter(highlighter);
} catch (Throwable e) {
LOG.warn(e);
}
}
Aggregations