Search in sources :

Example 36 with EditorHighlighter

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;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 37 with EditorHighlighter

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());
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 38 with EditorHighlighter

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
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Document(com.intellij.openapi.editor.Document) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 39 with EditorHighlighter

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();
}
Also used : RichCopySettings(com.intellij.openapi.editor.richcopy.settings.RichCopySettings) SyntaxInfo(com.intellij.openapi.editor.richcopy.model.SyntaxInfo) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with EditorHighlighter

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);
    }
}
Also used : Language(com.intellij.lang.Language) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Aggregations

EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)63 EditorEx (com.intellij.openapi.editor.ex.EditorEx)36 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)36 Document (com.intellij.openapi.editor.Document)13 IElementType (com.intellij.psi.tree.IElementType)11 Editor (com.intellij.openapi.editor.Editor)8 FileType (com.intellij.openapi.fileTypes.FileType)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)8 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 PsiFile (com.intellij.psi.PsiFile)7 LexerEditorHighlighter (com.intellij.openapi.editor.ex.util.LexerEditorHighlighter)6 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)5 PsiElement (com.intellij.psi.PsiElement)5 Language (com.intellij.lang.Language)4 CaretModel (com.intellij.openapi.editor.CaretModel)4 Project (com.intellij.openapi.project.Project)4 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)3 EditorWindow (com.intellij.injected.editor.EditorWindow)3 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)3