From 58dbbaa7b1386737b07f789b621d8a1c4bb5dcf0 Mon Sep 17 00:00:00 2001 From: Dmitry Batrak Date: Wed, 25 Jul 2018 19:11:02 +0300 Subject: [PATCH] bring back the API to mute highlighters in collapsed fold region --- .../diff/tools/util/FoldingModelSupport.java | 3 +-- .../intellij/openapi/editor/FoldRegion.java | 13 +++++++++++++ .../openapi/editor/ex/RangeHighlighterEx.java | 3 +++ .../openapi/editor/impl/FoldRegionImpl.java | 13 +++++++++++++ .../editor/impl/view/EditorPainter.java | 18 +----------------- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java b/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java index 115a7b13f77d..d918013a64e0 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/util/FoldingModelSupport.java @@ -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; } diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/FoldRegion.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/FoldRegion.java index 59d2230a236d..6217c2d4f04a 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/FoldRegion.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/FoldRegion.java @@ -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. + *

+ * 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; } } diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/RangeHighlighterEx.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/RangeHighlighterEx.java index 37510e448db0..6d558bb4143e 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/RangeHighlighterEx.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/ex/RangeHighlighterEx.java @@ -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(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java index b4a0e062763e..6450f0830ec6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldRegionImpl.java @@ -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 { + private static final Key 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 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 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); }