use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class NavigationUtil method patchAttributesColor.
/**
* Patches attributes to be visible under debugger active line
*/
@SuppressWarnings("UseJBColor")
public static TextAttributes patchAttributesColor(TextAttributes attributes, @NotNull TextRange range, @NotNull Editor editor) {
if (attributes.getForegroundColor() == null && attributes.getEffectColor() == null)
return attributes;
MarkupModel model = DocumentMarkupModel.forDocument(editor.getDocument(), editor.getProject(), false);
if (model != null) {
if (!((MarkupModelEx) model).processRangeHighlightersOverlappingWith(range.getStartOffset(), range.getEndOffset(), highlighter -> {
if (highlighter.isValid() && highlighter.getTargetArea() == HighlighterTargetArea.LINES_IN_RANGE) {
TextAttributes textAttributes = highlighter.getTextAttributes();
if (textAttributes != null) {
Color color = textAttributes.getBackgroundColor();
return !(color != null && color.getBlue() > 128 && color.getRed() < 128 && color.getGreen() < 128);
}
}
return true;
})) {
TextAttributes clone = attributes.clone();
clone.setForegroundColor(Color.orange);
clone.setEffectColor(Color.orange);
return clone;
}
}
return attributes;
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class ConsoleViewImpl method findTokenMarker.
// finds range marker the [offset..offset+1) belongs to
private RangeMarker findTokenMarker(int offset) {
RangeMarker[] marker = new RangeMarker[1];
MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(myEditor.getDocument(), getProject(), true);
model.processRangeHighlightersOverlappingWith(offset, offset, m -> {
if (getTokenType(m) == null || m.getStartOffset() > offset || offset + 1 > m.getEndOffset())
return true;
marker[0] = m;
return false;
});
return marker[0];
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong.
public void testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong() throws Throwable {
String text = "class X{\nint xxx;\n{\nint i = <selection>null</selection><caret>;\n" + StringUtil.repeat("{ this.hashCode(); }\n\n\n", 10000) + "}}";
configureByText(StdFileTypes.JAVA, text);
((EditorImpl) myEditor).getScrollPane().getViewport().setSize(100, 100);
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
((EditorImpl) myEditor).getScrollPane().getViewport().setViewPosition(new Point(0, 0));
((EditorImpl) myEditor).getScrollPane().getViewport().setExtentSize(new Dimension(100, 100000));
ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(getEditor());
assertTrue(visibleRange.getLength() > 0);
final Document document = myEditor.getDocument();
assertTrue(visibleRange.getLength() < document.getTextLength());
List<HighlightInfo> err1 = highlightErrors();
HighlightInfo info = assertOneElement(err1);
final String errorDescription = "Incompatible types. Found: 'null', required: 'int'";
assertEquals(errorDescription, info.getDescription());
MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, false);
final boolean[] errorRemoved = { false };
model.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {
@Override
public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
Object tt = highlighter.getErrorStripeTooltip();
if (!(tt instanceof HighlightInfo))
return;
String description = ((HighlightInfo) tt).getDescription();
if (errorDescription.equals(description)) {
errorRemoved[0] = true;
List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
GeneralHighlightingPass ghp = null;
for (TextEditorHighlightingPass pass : passes) {
if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) {
assert ghp == null : ghp;
ghp = (GeneralHighlightingPass) pass;
}
}
assertNotNull(ghp);
boolean finished = ghp.isFinished();
assertFalse(finished);
}
}
});
type("1");
List<HighlightInfo> errors = highlightErrors();
assertEmpty(errors);
assertTrue(errorRemoved[0]);
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testTypeParametersMustNotBlinkWhenTypingInsideClass.
public void testTypeParametersMustNotBlinkWhenTypingInsideClass() throws Throwable {
configureByText(JavaFileType.INSTANCE, "package x; \n" + "abstract class ToRun<TTTTTTTTTTTTTTT> implements Comparable<TTTTTTTTTTTTTTT> {\n" + " private ToRun<TTTTTTTTTTTTTTT> delegate;\n" + " <caret>\n" + " \n" + "}");
List<HighlightInfo> errors = highlightErrors();
assertEmpty(errors);
MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {
@Override
public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
if (TextRange.create(highlighter).substring(highlighter.getDocument().getText()).equals("TTTTTTTTTTTTTTT")) {
throw new RuntimeException("Must not remove type parameter highlighter");
}
}
});
assertEmpty(highlightErrors());
type("//xxx");
assertEmpty(highlightErrors());
backspace();
assertEmpty(highlightErrors());
backspace();
assertEmpty(highlightErrors());
backspace();
assertEmpty(highlightErrors());
backspace();
backspace();
assertEmpty(highlightErrors());
}
use of com.intellij.openapi.editor.ex.MarkupModelEx in project intellij-community by JetBrains.
the class EditorPainter method paint.
void paint(Graphics2D g) {
Rectangle clip = g.getClipBounds();
if (myEditor.getContentComponent().isOpaque()) {
g.setColor(myEditor.getBackgroundColor());
g.fillRect(clip.x, clip.y, clip.width, clip.height);
}
if (paintPlaceholderText(g)) {
paintCaret(g);
return;
}
int startLine = myView.yToVisualLine(clip.y);
int endLine = myView.yToVisualLine(clip.y + clip.height);
int startOffset = myView.visualLineToOffset(startLine);
int endOffset = myView.visualLineToOffset(endLine + 1);
ClipDetector clipDetector = new ClipDetector(myEditor, clip);
IterationState.CaretData caretData = myEditor.isPaintSelection() ? IterationState.createCaretData(myEditor) : null;
paintBackground(g, clip, startLine, endLine, caretData);
paintRightMargin(g, clip);
paintCustomRenderers(g, startOffset, endOffset);
MarkupModelEx docMarkup = myEditor.getFilteredDocumentMarkupModel();
paintLineMarkersSeparators(g, clip, docMarkup, startOffset, endOffset);
paintLineMarkersSeparators(g, clip, myEditor.getMarkupModel(), startOffset, endOffset);
paintTextWithEffects(g, clip, startLine, endLine, caretData);
paintHighlightersAfterEndOfLine(g, docMarkup, startOffset, endOffset);
paintHighlightersAfterEndOfLine(g, myEditor.getMarkupModel(), startOffset, endOffset);
paintBorderEffect(g, clipDetector, myEditor.getHighlighter(), startOffset, endOffset);
paintBorderEffect(g, clipDetector, docMarkup, startOffset, endOffset);
paintBorderEffect(g, clipDetector, myEditor.getMarkupModel(), startOffset, endOffset);
paintCaret(g);
paintComposedTextDecoration(g);
}
Aggregations