use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class Bookmark method getLine.
public int getLine() {
int targetLine = myTarget.getLine();
if (targetLine == -1)
return targetLine;
//What user sees in gutter
RangeHighlighterEx highlighter = findMyHighlighter();
if (highlighter != null && highlighter.isValid()) {
Document document = getDocument();
if (document != null) {
return document.getLineNumber(highlighter.getStartOffset());
}
}
RangeMarker marker = myTarget.getRangeMarker();
if (marker != null && marker.isValid()) {
Document document = marker.getDocument();
return document.getLineNumber(marker.getStartOffset());
}
return targetLine;
}
use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class Bookmark method findMyHighlighter.
private RangeHighlighterEx findMyHighlighter() {
final Document document = getDocument();
if (document == null)
return null;
RangeHighlighterEx result = SoftReference.dereference(myHighlighterRef);
if (result != null) {
return result;
}
MarkupModelEx markup = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, true);
final Document markupDocument = markup.getDocument();
final int startOffset = 0;
final int endOffset = markupDocument.getTextLength();
final Ref<RangeHighlighterEx> found = new Ref<>();
markup.processRangeHighlightersOverlappingWith(startOffset, endOffset, highlighter -> {
GutterMark renderer = highlighter.getGutterIconRenderer();
if (renderer instanceof MyGutterIconRenderer && ((MyGutterIconRenderer) renderer).myBookmark == this) {
found.set(highlighter);
return false;
}
return true;
});
result = found.get();
myHighlighterRef = result == null ? null : new WeakReference<>(result);
return result;
}
use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class Bookmark method createHighlighter.
public RangeHighlighter createHighlighter(@NotNull MarkupModelEx markup) {
final RangeHighlighterEx highlighter;
int line = getLine();
if (line >= 0) {
highlighter = markup.addPersistentLineHighlighter(line, HighlighterLayer.ERROR + 1, null);
if (highlighter != null) {
highlighter.setGutterIconRenderer(new MyGutterIconRenderer(this));
TextAttributes textAttributes = ObjectUtils.notNull(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BOOKMARKS_ATTRIBUTES), new TextAttributes());
Color stripeColor = ObjectUtils.notNull(textAttributes.getErrorStripeColor(), new JBColor(0x000000, 0xdbdbdb));
highlighter.setErrorStripeMarkColor(stripeColor);
highlighter.setErrorStripeTooltip(getBookmarkTooltip());
TextAttributes attributes = highlighter.getTextAttributes();
if (attributes == null) {
attributes = new TextAttributes();
}
attributes.setBackgroundColor(textAttributes.getBackgroundColor());
attributes.setForegroundColor(textAttributes.getForegroundColor());
highlighter.setTextAttributes(attributes);
}
} else {
highlighter = null;
}
myHighlighterRef = highlighter == null ? null : new WeakReference<>(highlighter);
return highlighter;
}
use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class Bookmark method release.
public void release() {
int line = getLine();
if (line < 0) {
return;
}
final Document document = getDocument();
if (document == null)
return;
MarkupModelEx markup = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, true);
final Document markupDocument = markup.getDocument();
if (markupDocument.getLineCount() <= line)
return;
RangeHighlighterEx highlighter = findMyHighlighter();
if (highlighter != null) {
myHighlighterRef = null;
highlighter.dispose();
}
}
use of com.intellij.openapi.editor.ex.RangeHighlighterEx in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testLineMarkersDoNotBlinkOnBackSpaceRightBeforeMethodIdentifier.
public void testLineMarkersDoNotBlinkOnBackSpaceRightBeforeMethodIdentifier() throws Throwable {
configureByText(JavaFileType.INSTANCE, "package x; \n" + "class <caret>ToRun{\n" + " public static void main(String[] args) {\n" + " }\n" + "}");
List<HighlightInfo> errors = highlightErrors();
assertEmpty(errors);
List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
assertSize(2, lineMarkers);
backspace();
final Collection<String> changed = new ArrayList<>();
MarkupModelEx modelEx = (MarkupModelEx) DocumentMarkupModel.forDocument(getDocument(getFile()), getProject(), true);
modelEx.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener() {
@Override
public void afterAdded(@NotNull RangeHighlighterEx highlighter) {
changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("after added")));
}
@Override
public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("before removed")));
}
@Override
public void attributesChanged(@NotNull RangeHighlighterEx highlighter, boolean renderersChanged, boolean fontStyleChanged) {
changed(highlighter, ExceptionUtil.getThrowableText(new Throwable("changed")));
}
private void changed(@NotNull RangeHighlighterEx highlighter, String reason) {
// not line marker
if (highlighter.getTargetArea() != HighlighterTargetArea.LINES_IN_RANGE)
return;
List<LineMarkerInfo> lineMarkers = DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject());
// not line marker
if (ContainerUtil.find(lineMarkers, lm -> lm.highlighter == highlighter) == null)
return;
changed.add(highlighter + ": \n" + reason);
}
});
assertEmpty(highlightErrors());
assertSize(2, DaemonCodeAnalyzerImpl.getLineMarkers(myEditor.getDocument(), getProject()));
assertEmpty(changed);
}
Aggregations