mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
editor: allow to disable RangeHighlighters from DocumentMarkupModel in a single editor
This commit is contained in:
+8
-4
@@ -18,7 +18,6 @@ package com.intellij.openapi.editor.impl;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.ex.MarkupIterator;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.ex.MarkupModelEx;
|
||||
import com.intellij.openapi.editor.ex.RangeHighlighterEx;
|
||||
import com.intellij.openapi.editor.impl.event.MarkupModelListener;
|
||||
@@ -38,7 +37,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class EditorFilteringMarkupModelEx implements MarkupModelEx {
|
||||
@NotNull private final EditorEx myEditor;
|
||||
@NotNull private final EditorImpl myEditor;
|
||||
@NotNull private final MarkupModelEx myDelegate;
|
||||
|
||||
private final Condition<RangeHighlighter> IS_AVAILABLE = new Condition<RangeHighlighter>() {
|
||||
@@ -48,13 +47,18 @@ public class EditorFilteringMarkupModelEx implements MarkupModelEx {
|
||||
}
|
||||
};
|
||||
|
||||
public EditorFilteringMarkupModelEx(@NotNull EditorEx editor, @NotNull MarkupModelEx delegate) {
|
||||
public EditorFilteringMarkupModelEx(@NotNull EditorImpl editor, @NotNull MarkupModelEx delegate) {
|
||||
myEditor = editor;
|
||||
myDelegate = delegate;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MarkupModelEx getDelegate() {
|
||||
return myDelegate;
|
||||
}
|
||||
|
||||
private boolean isAvailable(@NotNull RangeHighlighter highlighter) {
|
||||
return highlighter.getEditorFilter().avaliableIn(myEditor);
|
||||
return highlighter.getEditorFilter().avaliableIn(myEditor) && myEditor.isHighlighterAvailable(highlighter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -191,7 +191,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
private boolean myIsViewer;
|
||||
@NotNull private final SelectionModelImpl mySelectionModel;
|
||||
@NotNull private final EditorMarkupModelImpl myMarkupModel;
|
||||
@NotNull private final MarkupModelEx myDocumentMarkupModel;
|
||||
@NotNull private final EditorFilteringMarkupModelEx myDocumentMarkupModel;
|
||||
@NotNull private final MarkupModelListener myMarkupModelListener;
|
||||
|
||||
@NotNull private final FoldingModelImpl myFoldingModel;
|
||||
@NotNull private final ScrollingModelImpl myScrollingModel;
|
||||
@@ -274,6 +275,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
|
||||
private EditorDropHandler myDropHandler;
|
||||
|
||||
private Condition<RangeHighlighter> myHighlightingFilter;
|
||||
|
||||
private char[] myPrefixText;
|
||||
private TextAttributes myPrefixAttributes;
|
||||
private int myPrefixWidthInPixels;
|
||||
@@ -362,7 +365,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
myConnection.subscribe(DocumentBulkUpdateListener.TOPIC, new EditorDocumentBulkUpdateAdapter());
|
||||
}
|
||||
|
||||
MarkupModelListener markupModelListener = new MarkupModelListener() {
|
||||
myMarkupModelListener = new MarkupModelListener() {
|
||||
private boolean areRenderersInvolved(@NotNull RangeHighlighterEx highlighter) {
|
||||
return highlighter.getCustomRenderer() != null ||
|
||||
highlighter.getGutterIconRenderer() != null ||
|
||||
@@ -423,8 +426,8 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
}
|
||||
};
|
||||
|
||||
getFilteredDocumentMarkupModel().addMarkupModelListener(myCaretModel, markupModelListener);
|
||||
getMarkupModel().addMarkupModelListener(myCaretModel, markupModelListener);
|
||||
getFilteredDocumentMarkupModel().addMarkupModelListener(myCaretModel, myMarkupModelListener);
|
||||
getMarkupModel().addMarkupModelListener(myCaretModel, myMarkupModelListener);
|
||||
|
||||
myDocument.addDocumentListener(myFoldingModel, myCaretModel);
|
||||
myDocument.addDocumentListener(myCaretModel, myCaretModel);
|
||||
@@ -5482,6 +5485,21 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
|
||||
myDropHandler = dropHandler;
|
||||
}
|
||||
|
||||
public void setHighlightingFilter(@Nullable Condition<RangeHighlighter> filter) {
|
||||
if (myHighlightingFilter == filter) return;
|
||||
Condition<RangeHighlighter> oldFilter = myHighlightingFilter;
|
||||
myHighlightingFilter = filter;
|
||||
|
||||
for (RangeHighlighter highlighter : myDocumentMarkupModel.getDelegate().getAllHighlighters()) {
|
||||
boolean oldAvailable = oldFilter == null || oldFilter.value(highlighter);
|
||||
boolean newAvailable = filter == null || filter.value(highlighter);
|
||||
if (oldAvailable != newAvailable) myMarkupModelListener.attributesChanged((RangeHighlighterEx)highlighter, true);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHighlighterAvailable(@NotNull RangeHighlighter highlighter) {
|
||||
return myHighlightingFilter == null || myHighlightingFilter.value(highlighter);
|
||||
}
|
||||
|
||||
private static class MyInputMethodHandleSwingThreadWrapper implements InputMethodRequests {
|
||||
private final InputMethodRequests myDelegate;
|
||||
|
||||
Reference in New Issue
Block a user