Search in sources :

Example 6 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class DocumentMarkupModelTest method testInfoTestAttributes.

public void testInfoTestAttributes() throws Exception {
    LanguageExtensionPoint<Annotator> extension = new LanguageExtensionPoint<>();
    extension.language = "TEXT";
    extension.implementationClass = TestAnnotator.class.getName();
    PlatformTestUtil.registerExtension(ExtensionPointName.create(LanguageAnnotators.EP_NAME), extension, myFixture.getTestRootDisposable());
    myFixture.configureByText(PlainTextFileType.INSTANCE, "foo");
    EditorColorsScheme scheme = new EditorColorsSchemeImpl(new DefaultColorsScheme()) {

        {
            initFonts();
        }
    };
    scheme.setAttributes(HighlighterColors.TEXT, new TextAttributes(Color.black, Color.white, null, null, Font.PLAIN));
    ((EditorEx) myFixture.getEditor()).setColorsScheme(scheme);
    myFixture.doHighlighting();
    MarkupModel model = DocumentMarkupModel.forDocument(myFixture.getEditor().getDocument(), getProject(), false);
    RangeHighlighter[] highlighters = model.getAllHighlighters();
    assertThat(highlighters).hasSize(1);
    TextAttributes attributes = highlighters[0].getTextAttributes();
    assertThat(attributes).isNotNull();
    assertThat(attributes.getBackgroundColor()).isNull();
    assertThat(attributes.getForegroundColor()).isNull();
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Annotator(com.intellij.lang.annotation.Annotator) EditorColorsSchemeImpl(com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl) DefaultColorsScheme(com.intellij.openapi.editor.colors.impl.DefaultColorsScheme) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) LanguageExtensionPoint(com.intellij.lang.LanguageExtensionPoint) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 7 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class RangeMarkerTest method testRangeHighlightersRecreateBug.

public void testRangeHighlightersRecreateBug() throws Exception {
    Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");
    MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
    for (int i = 0; i < 2; i++) {
        RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
        RangeMarker m2 = markupModel.addRangeHighlighter(2, 7, 0, null, HighlighterTargetArea.EXACT_RANGE);
        RangeMarker m3 = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
        markupModel.removeAllHighlighters();
    }
}
Also used : MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 8 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class RangeMarkerTest method testRangeHighlighterDisposeVsRemoveAllConflict.

public void testRangeHighlighterDisposeVsRemoveAllConflict() throws Exception {
    Document document = EditorFactory.getInstance().createDocument("[xxxxxxxxxxxxxx]");
    MarkupModel markupModel = DocumentMarkupModel.forDocument(document, ourProject, true);
    RangeMarker m = markupModel.addRangeHighlighter(1, 6, 0, null, HighlighterTargetArea.EXACT_RANGE);
    assertTrue(m.isValid());
    markupModel.removeAllHighlighters();
    assertFalse(m.isValid());
    assertEmpty(markupModel.getAllHighlighters());
    m.dispose();
    assertFalse(m.isValid());
}
Also used : MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 9 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class IdentifierHighlighterPass method clearMyHighlights.

public static void clearMyHighlights(Document document, Project project) {
    MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);
    for (RangeHighlighter highlighter : markupModel.getAllHighlighters()) {
        Object tooltip = highlighter.getErrorStripeTooltip();
        if (!(tooltip instanceof HighlightInfo)) {
            continue;
        }
        HighlightInfo info = (HighlightInfo) tooltip;
        if (info.type == HighlightInfoType.ELEMENT_UNDER_CARET_READ || info.type == HighlightInfoType.ELEMENT_UNDER_CARET_WRITE) {
            highlighter.dispose();
        }
    }
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Example 10 with MarkupModel

use of com.intellij.openapi.editor.markup.MarkupModel in project intellij-community by JetBrains.

the class IndentsPass method doApplyInformationToEditor.

@Override
public void doApplyInformationToEditor() {
    final Long stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT);
    if (stamp != null && stamp.longValue() == nowStamp())
        return;
    List<RangeHighlighter> oldHighlighters = myEditor.getUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY);
    final List<RangeHighlighter> newHighlighters = new ArrayList<>();
    final MarkupModel mm = myEditor.getMarkupModel();
    int curRange = 0;
    if (oldHighlighters != null) {
        int curHighlight = 0;
        while (curRange < myRanges.size() && curHighlight < oldHighlighters.size()) {
            TextRange range = myRanges.get(curRange);
            RangeHighlighter highlighter = oldHighlighters.get(curHighlight);
            int cmp = compare(range, highlighter);
            if (cmp < 0) {
                newHighlighters.add(createHighlighter(mm, range));
                curRange++;
            } else if (cmp > 0) {
                highlighter.dispose();
                curHighlight++;
            } else {
                newHighlighters.add(highlighter);
                curHighlight++;
                curRange++;
            }
        }
        for (; curHighlight < oldHighlighters.size(); curHighlight++) {
            RangeHighlighter highlighter = oldHighlighters.get(curHighlight);
            highlighter.dispose();
        }
    }
    final int startRangeIndex = curRange;
    assert myDocument != null;
    DocumentUtil.executeInBulk(myDocument, myRanges.size() > 10000, () -> {
        for (int i = startRangeIndex; i < myRanges.size(); i++) {
            newHighlighters.add(createHighlighter(mm, myRanges.get(i)));
        }
    });
    myEditor.putUserData(INDENT_HIGHLIGHTERS_IN_EDITOR_KEY, newHighlighters);
    myEditor.putUserData(LAST_TIME_INDENTS_BUILT, nowStamp());
    myEditor.getIndentsModel().assumeIndents(myDescriptors);
}
Also used : RangeHighlighter(com.intellij.openapi.editor.markup.RangeHighlighter) TextRange(com.intellij.openapi.util.TextRange) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel)

Aggregations

MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)23 DocumentMarkupModel (com.intellij.openapi.editor.impl.DocumentMarkupModel)12 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)10 Editor (com.intellij.openapi.editor.Editor)8 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)8 Project (com.intellij.openapi.project.Project)8 TextRange (com.intellij.openapi.util.TextRange)8 List (java.util.List)6 NotNull (org.jetbrains.annotations.NotNull)5 Document (com.intellij.openapi.editor.Document)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 ArrayList (java.util.ArrayList)4 javax.swing (javax.swing)4 Segment (com.intellij.openapi.util.Segment)3 HighlightInfo (com.intellij.codeInsight.daemon.impl.HighlightInfo)2 EditorFactory (com.intellij.openapi.editor.EditorFactory)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 MarkupModelEx (com.intellij.openapi.editor.ex.MarkupModelEx)2 RangeHighlighterEx (com.intellij.openapi.editor.ex.RangeHighlighterEx)2 EditorUtil (com.intellij.openapi.editor.ex.util.EditorUtil)2