diff --git a/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffChange.java b/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffChange.java index 662216e88724..45c14d6f770f 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffChange.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/fragmented/UnifiedDiffChange.java @@ -137,15 +137,15 @@ public class UnifiedDiffChange { } private void createHighlighter(@NotNull TextDiffType type, int start, int end, boolean ignored) { - myHighlighters.add(DiffDrawUtil.createHighlighter(myEditor, start, end, type, ignored)); + myHighlighters.addAll(DiffDrawUtil.createHighlighter(myEditor, start, end, type, ignored)); } private void createInlineHighlighter(@NotNull TextDiffType type, int start, int end) { - myHighlighters.add(DiffDrawUtil.createInlineHighlighter(myEditor, start, end, type)); + myHighlighters.addAll(DiffDrawUtil.createInlineHighlighter(myEditor, start, end, type)); } private void createLineMarker(@NotNull TextDiffType type, int line, @NotNull SeparatorPlacement placement) { - myHighlighters.add(DiffDrawUtil.createLineMarker(myEditor, line, type, placement)); + myHighlighters.addAll(DiffDrawUtil.createLineMarker(myEditor, line, type, placement)); } public int getLine1() { diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java index 5f7752fb0eca..b74404321523 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleDiffChange.java @@ -115,17 +115,17 @@ public class SimpleDiffChange { int end = side.getEndOffset(myFragment); TextDiffType type = DiffUtil.getLineDiffType(myFragment); - myHighlighters.add(DiffDrawUtil.createHighlighter(editor, start, end, type, ignored)); + myHighlighters.addAll(DiffDrawUtil.createHighlighter(editor, start, end, type, ignored)); int startLine = side.getStartLine(myFragment); int endLine = side.getEndLine(myFragment); if (startLine == endLine) { - if (startLine != 0) myHighlighters.add(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM, true)); + if (startLine != 0) myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM, true)); } else { - myHighlighters.add(DiffDrawUtil.createLineMarker(editor, startLine, type, SeparatorPlacement.TOP)); - myHighlighters.add(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM)); + myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, startLine, type, SeparatorPlacement.TOP)); + myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM)); } } @@ -139,8 +139,7 @@ public class SimpleDiffChange { end += startOffset; Editor editor = myViewer.getEditor(side); - RangeHighlighter highlighter = DiffDrawUtil.createInlineHighlighter(editor, start, end, type); - myHighlighters.add(highlighter); + myHighlighters.addAll(DiffDrawUtil.createInlineHighlighter(editor, start, end, type)); } public void updateGutterActions(boolean force) { diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleOnesideDiffViewer.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleOnesideDiffViewer.java index 8f7fae09a4c1..ad630c48639b 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleOnesideDiffViewer.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleOnesideDiffViewer.java @@ -133,14 +133,14 @@ public class SimpleOnesideDiffViewer extends OnesideTextDiffViewer { int end = document.getTextLength(); TextDiffType type = getSide().select(TextDiffType.DELETED, TextDiffType.INSERTED); - myHighlighters.add(DiffDrawUtil.createHighlighter(getEditor(), start, end, type, false)); + myHighlighters.addAll(DiffDrawUtil.createHighlighter(getEditor(), start, end, type, false)); int startLine = 0; int endLine = getLineCount(document); if (startLine != endLine) { - myHighlighters.add(DiffDrawUtil.createLineMarker(getEditor(), startLine, type, SeparatorPlacement.TOP)); - myHighlighters.add(DiffDrawUtil.createLineMarker(getEditor(), endLine - 1, type, SeparatorPlacement.BOTTOM)); + myHighlighters.addAll(DiffDrawUtil.createLineMarker(getEditor(), startLine, type, SeparatorPlacement.TOP)); + myHighlighters.addAll(DiffDrawUtil.createLineMarker(getEditor(), endLine - 1, type, SeparatorPlacement.BOTTOM)); } } diff --git a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java index 6dc7b9856c94..b5a240ce5bf2 100644 --- a/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java +++ b/platform/diff-impl/src/com/intellij/diff/tools/simple/SimpleThreesideDiffChange.java @@ -92,14 +92,14 @@ public class SimpleThreesideDiffChange { if (end < document.getTextLength()) end++; } - myHighlighters.add(DiffDrawUtil.createHighlighter(editor, start, end, type)); + myHighlighters.addAll(DiffDrawUtil.createHighlighter(editor, start, end, type)); if (startLine == endLine) { - if (startLine != 0) myHighlighters.add(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM, true)); + if (startLine != 0) myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM, true)); } else { - myHighlighters.add(DiffDrawUtil.createLineMarker(editor, startLine, type, SeparatorPlacement.TOP)); - myHighlighters.add(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM)); + myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, startLine, type, SeparatorPlacement.TOP)); + myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, endLine - 1, type, SeparatorPlacement.BOTTOM)); } } 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 5f7c35df2be5..859aa59a06fd 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 @@ -634,9 +634,9 @@ public class FoldingModelSupport { for (int i = 0; i < myCount; i++) { FoldRegion region = myRegions[i]; if (region == null || !region.isValid()) continue; - myHighlighters.add(DiffDrawUtil.createLineSeparatorHighlighter(myEditors[i], - region.getStartOffset(), region.getEndOffset(), - getHighlighterCondition(block, i))); + myHighlighters.addAll(DiffDrawUtil.createLineSeparatorHighlighter(myEditors[i], + region.getStartOffset(), region.getEndOffset(), + getHighlighterCondition(block, i))); } } diff --git a/platform/diff-impl/src/com/intellij/diff/util/DiffDrawUtil.java b/platform/diff-impl/src/com/intellij/diff/util/DiffDrawUtil.java index 5b7adf9eed68..ac4f0f940391 100644 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffDrawUtil.java +++ b/platform/diff-impl/src/com/intellij/diff/util/DiffDrawUtil.java @@ -23,6 +23,7 @@ import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.util.BooleanGetter; import com.intellij.ui.JBColor; import com.intellij.util.DocumentUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,8 +31,15 @@ import org.jetbrains.annotations.Nullable; import java.awt.*; import java.awt.geom.CubicCurve2D; import java.awt.geom.Path2D; +import java.util.Collections; +import java.util.List; public class DiffDrawUtil { + private static final int STRIPE_LAYER = HighlighterLayer.ERROR - 1; + private static final int DEFAULT_LAYER = HighlighterLayer.SELECTION - 3; + private static final int INLINE_LAYER = HighlighterLayer.SELECTION - 2; + private static final int LINE_MARKER_LAYER = HighlighterLayer.SELECTION - 1; + private DiffDrawUtil() { } @@ -166,18 +174,12 @@ public class DiffDrawUtil { @NotNull private static TextAttributes getTextAttributes(@NotNull final TextDiffType type, @Nullable final Editor editor, - final boolean ignored, - final boolean showStripes) { + final boolean ignored) { return new TextAttributes() { @Override public Color getBackgroundColor() { return ignored ? type.getIgnoredColor(editor) : type.getColor(editor); } - - @Override - public Color getErrorStripeColor() { - return showStripes ? type.getMarkerColor(editor) : null; - } }; } @@ -212,55 +214,57 @@ public class DiffDrawUtil { // TODO: desync of range and line markers @NotNull - public static RangeHighlighter createHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type) { + public static List createHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type) { return createHighlighter(editor, start, end, type, false); } @NotNull - public static RangeHighlighter createHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type, - boolean ignored) { + public static List createHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type, + boolean ignored) { return createHighlighter(editor, start, end, type, ignored, HighlighterTargetArea.EXACT_RANGE); } @NotNull - public static RangeHighlighter createHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type, - boolean ignored, @NotNull HighlighterTargetArea area) { - TextAttributes attributes = getTextAttributes(type, editor, ignored, true); + public static List createHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type, + boolean ignored, @NotNull HighlighterTargetArea area) { + TextAttributes attributes = start != end ? getTextAttributes(type, editor, ignored) : null; + TextAttributes stripeAttributes = start != end ? getStripeTextAttributes(type, editor) : null; - RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(start, end, HighlighterLayer.SELECTION - 3, - start != end ? attributes : null, area); - - // TODO: diff looks cool with wide markers. Maybe we can keep them ? - highlighter.setThinErrorStripeMark(true); + RangeHighlighter highlighter = editor.getMarkupModel() + .addRangeHighlighter(start, end, DEFAULT_LAYER, attributes, area); installGutterRenderer(highlighter, type, ignored); - return highlighter; + if (stripeAttributes == null) return Collections.singletonList(highlighter); + + RangeHighlighter stripeHighlighter = editor.getMarkupModel() + .addRangeHighlighter(start, end, STRIPE_LAYER, stripeAttributes, area); + + return ContainerUtil.list(highlighter, stripeHighlighter); } @NotNull - public static RangeHighlighter createInlineHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type) { - TextAttributes attributes = getTextAttributes(type, editor, false, false); + public static List createInlineHighlighter(@NotNull Editor editor, int start, int end, @NotNull TextDiffType type) { + TextAttributes attributes = getTextAttributes(type, editor, false); RangeHighlighter highlighter = editor.getMarkupModel() - .addRangeHighlighter(start, end, HighlighterLayer.SELECTION - 2, attributes, HighlighterTargetArea.EXACT_RANGE); + .addRangeHighlighter(start, end, INLINE_LAYER, attributes, HighlighterTargetArea.EXACT_RANGE); if (start == end) installEmptyRangeRenderer(highlighter, type); - return highlighter; + return Collections.singletonList(highlighter); } @NotNull - public static RangeHighlighter createLineMarker(@NotNull Editor editor, int line, @NotNull final TextDiffType type, - @NotNull final SeparatorPlacement placement) { + public static List createLineMarker(@NotNull Editor editor, int line, @NotNull final TextDiffType type, + @NotNull final SeparatorPlacement placement) { return createLineMarker(editor, line, type, placement, false); } @NotNull - public static RangeHighlighter createLineMarker(@NotNull final Editor editor, int line, @NotNull final TextDiffType type, - @NotNull final SeparatorPlacement placement, final boolean doubleLine) { - TextAttributes attributes = getStripeTextAttributes(type, editor); + public static List createLineMarker(@NotNull final Editor editor, int line, @NotNull final TextDiffType type, + @NotNull final SeparatorPlacement placement, final boolean doubleLine) { LineSeparatorRenderer renderer = new LineSeparatorRenderer() { @Override public void drawLine(Graphics g, int x1, int x2, int y) { @@ -275,12 +279,12 @@ public class DiffDrawUtil { } } }; - return createLineMarker(editor, line, placement, attributes, renderer); + return createLineMarker(editor, line, placement, type, renderer); } @NotNull - public static RangeHighlighter createBorderLineMarker(@NotNull final Editor editor, int line, - @NotNull final SeparatorPlacement placement) { + public static List createBorderLineMarker(@NotNull final Editor editor, int line, + @NotNull final SeparatorPlacement placement) { LineSeparatorRenderer renderer = new LineSeparatorRenderer() { @Override public void drawLine(Graphics g, int x1, int x2, int y) { @@ -295,35 +299,40 @@ public class DiffDrawUtil { } @NotNull - public static RangeHighlighter createLineMarker(@NotNull final Editor editor, int line, @NotNull final SeparatorPlacement placement, - @Nullable TextAttributes attributes, @NotNull LineSeparatorRenderer renderer) { - int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line); - RangeHighlighter marker = editor.getMarkupModel().addRangeHighlighter(offset, offset, HighlighterLayer.SELECTION - 1, attributes, - HighlighterTargetArea.LINES_IN_RANGE); - marker.setThinErrorStripeMark(true); - + public static List createLineMarker(@NotNull final Editor editor, int line, @NotNull final SeparatorPlacement placement, + @Nullable TextDiffType type, @NotNull LineSeparatorRenderer renderer) { // We won't use addLineHighlighter as it will fail to add marker into empty document. - //RangeHighlighter marker = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null); + //RangeHighlighter highlighter = editor.getMarkupModel().addLineHighlighter(line, HighlighterLayer.SELECTION - 1, null); - marker.setLineSeparatorPlacement(placement); - marker.setLineSeparatorRenderer(renderer); + int offset = DocumentUtil.getFirstNonSpaceCharOffset(editor.getDocument(), line); + RangeHighlighter highlighter = editor.getMarkupModel() + .addRangeHighlighter(offset, offset, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE); - return marker; + highlighter.setLineSeparatorPlacement(placement); + highlighter.setLineSeparatorRenderer(renderer); + + if (type == null) return Collections.singletonList(highlighter); + + TextAttributes stripeAttributes = getStripeTextAttributes(type, editor); + RangeHighlighter stripeHighlighter = editor.getMarkupModel() + .addRangeHighlighter(offset, offset, STRIPE_LAYER, stripeAttributes, HighlighterTargetArea.LINES_IN_RANGE); + + return ContainerUtil.list(highlighter, stripeHighlighter); } @NotNull - public static RangeHighlighter createLineSeparatorHighlighter(@NotNull Editor editor, - int offset1, - int offset2, - @NotNull BooleanGetter condition) { - RangeHighlighter marker = editor.getMarkupModel().addRangeHighlighter(offset1, offset2, HighlighterLayer.SELECTION - 1, null, - HighlighterTargetArea.LINES_IN_RANGE); + public static List createLineSeparatorHighlighter(@NotNull Editor editor, + int offset1, + int offset2, + @NotNull BooleanGetter condition) { + RangeHighlighter marker = editor.getMarkupModel() + .addRangeHighlighter(offset1, offset2, LINE_MARKER_LAYER, null, HighlighterTargetArea.LINES_IN_RANGE); DiffLineSeparatorRenderer renderer = new DiffLineSeparatorRenderer(editor, condition); marker.setLineSeparatorPlacement(SeparatorPlacement.TOP); marker.setLineSeparatorRenderer(renderer); marker.setLineMarkerRenderer(renderer); - return marker; + return Collections.singletonList(marker); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java index 5f042f4c49ea..315365356280 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/ex/LineStatusTrackerDrawing.java @@ -314,7 +314,7 @@ public class LineStatusTrackerDrawing { int currentEnd = currentStartShift + fragment.getEndOffset2(); TextDiffType type = DiffUtil.getDiffType(fragment); - highlighters.add(DiffDrawUtil.createInlineHighlighter(editor, currentStart, currentEnd, type)); + highlighters.addAll(DiffDrawUtil.createInlineHighlighter(editor, currentStart, currentEnd, type)); } Disposer.register(parentDisposable, new Disposable() {