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();
}
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();
}
}
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());
}
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();
}
}
}
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);
}
Aggregations