bring back the API to mute highlighters in collapsed fold region

This commit is contained in:
Dmitry Batrak
2018-07-25 19:18:50 +03:00
parent 3af65d8758
commit 58dbbaa7b1
5 changed files with 31 additions and 19 deletions
@@ -17,7 +17,6 @@ import com.intellij.openapi.editor.ex.DocumentEx;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.ex.FoldingListener;
import com.intellij.openapi.editor.ex.FoldingModelEx;
import com.intellij.openapi.editor.impl.view.EditorPainter;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.util.BooleanGetter;
import com.intellij.openapi.util.Key;
@@ -209,7 +208,7 @@ public class FoldingModelSupport {
FoldRegion value = editor.getFoldingModel().addFoldRegion(startOffset, endOffset, PLACEHOLDER);
if (value != null) {
value.setExpanded(expanded);
EditorPainter.muteInnerHighlighters(value);
value.setInnerHighlightersMuted(true);
}
return value;
}
@@ -41,4 +41,17 @@ public interface FoldRegion extends RangeMarker {
FoldingGroup getGroup();
boolean shouldNeverExpand();
/**
* If inner highlighters are muted for a collapsed fold region, there will not be a visual indication
* that region contains certain highlighters inside. By default such indication is added.
* <p>
* See also {@code isVisibleIfFolded()} method in {@code com.intellij.openapi.editor.ex.RangeHighlighterEx} class.
*/
default void setInnerHighlightersMuted(boolean value) {}
/**
* @see #setInnerHighlightersMuted(boolean)
*/
default boolean areInnerHighlightersMuted() { return false; }
}
@@ -2,6 +2,7 @@
package com.intellij.openapi.editor.ex;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.TextAttributes;
import org.jetbrains.annotations.NotNull;
@@ -27,6 +28,8 @@ public interface RangeHighlighterEx extends RangeHighlighter, RangeMarkerEx {
/**
* If {@code true}, there will be a visual indication that this highlighter is present inside a collapsed fold region.
* By default it won't happen, use {@link #setVisibleIfFolded(boolean)} to change it.
*
* @see FoldRegion#setInnerHighlightersMuted(boolean)
*/
boolean isVisibleIfFolded();
@@ -8,11 +8,14 @@ import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.FoldingGroup;
import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.util.Getter;
import com.intellij.openapi.util.Key;
import com.intellij.util.DocumentUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion, Getter<FoldRegionImpl> {
private static final Key<Boolean> MUTE_INNER_HIGHLIGHTERS = Key.create("mute.inner.highlighters");
private boolean myIsExpanded;
private final EditorImpl myEditor;
private final String myPlaceholderText;
@@ -155,6 +158,16 @@ class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion, Getter<FoldR
}
}
@Override
public void setInnerHighlightersMuted(boolean value) {
putUserData(MUTE_INNER_HIGHLIGHTERS, value ? Boolean.TRUE : null);
}
@Override
public boolean areInnerHighlightersMuted() {
return Boolean.TRUE.equals(getUserData(MUTE_INNER_HIGHLIGHTERS));
}
@Override
public void dispose() {
myEditor.getFoldingModel().removeRegionFromTree(this);
@@ -510,7 +510,7 @@ public class EditorPainter implements TextDrawingCallback {
@Nullable
private TextAttributes getInnerHighlighterAttributes(@NotNull FoldRegion region) {
if (areInnerHighlightersMuted(region)) return null;
if (region.areInnerHighlightersMuted()) return null;
List<RangeHighlighterEx> innerHighlighters = new ArrayList<>();
collectVisibleInnerHighlighters(region, myEditor.getMarkupModel(), innerHighlighters);
collectVisibleInnerHighlighters(region, myEditor.getFilteredDocumentMarkupModel(), innerHighlighters);
@@ -1049,22 +1049,6 @@ public class EditorPainter implements TextDrawingCallback {
}
}
/**
* If {@code Boolean.TRUE} value is set for this key on a collapsed fold region (see {@link #putUserData(Key, Object)}),
* there will not be a visual indication that region contains certain highlighters inside. By default such indication is added.
*
* @see RangeHighlighterImpl#VISIBLE_IF_FOLDED
*/
private static final Key<Boolean> MUTE_INNER_HIGHLIGHTERS = Key.create("mute.inner.highlighters");
public static void muteInnerHighlighters(@NotNull FoldRegion value) {
value.putUserData(MUTE_INNER_HIGHLIGHTERS, Boolean.TRUE);
}
private static boolean areInnerHighlightersMuted(@NotNull FoldRegion region) {
return Boolean.TRUE.equals(region.getUserData(MUTE_INNER_HIGHLIGHTERS));
}
private interface MarginWidthConsumer {
void process(float width);
}