From a32b8f4aad5c079c54df03d0ce4728f0ce5b0e16 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Thu, 2 Apr 2015 18:16:43 +0300 Subject: [PATCH] IDEA-135671 diff: better painting in gutter Paint half of folding outline in gutter like it is a part of editor --- .../com/intellij/diff/util/DiffDrawUtil.java | 13 +++++-- .../diff/util/DiffLineMarkerRenderer.java | 34 ++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) 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 12ea0b3b038a..ce9d6ae8f93c 100644 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffDrawUtil.java +++ b/platform/diff-impl/src/com/intellij/diff/util/DiffDrawUtil.java @@ -215,7 +215,7 @@ public class DiffDrawUtil { // TODO: diff looks cool with wide markers. Maybe we can keep them ? highlighter.setThinErrorStripeMark(true); - installGutterRenderer(highlighter, type); + installGutterRenderer(highlighter, type, ignored); return highlighter; } @@ -232,8 +232,15 @@ public class DiffDrawUtil { return highlighter; } - public static void installGutterRenderer(@NotNull RangeHighlighter highlighter, @NotNull TextDiffType type) { - highlighter.setLineMarkerRenderer(new DiffLineMarkerRenderer(type)); + public static void installGutterRenderer(@NotNull RangeHighlighter highlighter, + @NotNull TextDiffType type) { + installGutterRenderer(highlighter, type, false); + } + + public static void installGutterRenderer(@NotNull RangeHighlighter highlighter, + @NotNull TextDiffType type, + boolean ignoredFoldingOutline) { + highlighter.setLineMarkerRenderer(new DiffLineMarkerRenderer(type, ignoredFoldingOutline)); } public static void installEmptyRangeRenderer(@NotNull RangeHighlighter highlighter, @NotNull TextDiffType type) { diff --git a/platform/diff-impl/src/com/intellij/diff/util/DiffLineMarkerRenderer.java b/platform/diff-impl/src/com/intellij/diff/util/DiffLineMarkerRenderer.java index 09f8da940e7b..3589116171a7 100644 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffLineMarkerRenderer.java +++ b/platform/diff-impl/src/com/intellij/diff/util/DiffLineMarkerRenderer.java @@ -25,32 +25,50 @@ import java.awt.*; public class DiffLineMarkerRenderer implements LineMarkerRenderer { @NotNull private final TextDiffType myDiffType; + private final boolean myIgnoredFoldingOutline; public DiffLineMarkerRenderer(@NotNull TextDiffType diffType) { - myDiffType = diffType; + this(diffType, false); } + public DiffLineMarkerRenderer(@NotNull TextDiffType diffType, boolean ignoredFoldingOutline) { + myDiffType = diffType; + myIgnoredFoldingOutline = ignoredFoldingOutline; + } + + @Override public void paint(Editor editor, Graphics g, Rectangle range) { Color color = myDiffType.getColor(editor); EditorGutterComponentEx gutter = ((EditorEx)editor).getGutterComponentEx(); Graphics2D g2 = (Graphics2D)g; - int x = 0; + int x1 = 0; + int x2 = x1 + gutter.getWidth(); int y = range.y; - int width = gutter.getWidth(); int height = range.height; if (height > 2) { - g.setColor(color); - g.fillRect(x, y, width, height); - DiffDrawUtil.drawChunkBorderLine(g2, x, x + width, y - 1, color); - DiffDrawUtil.drawChunkBorderLine(g2, x, x + width, y + height - 1, color); + if (myIgnoredFoldingOutline) { + int xOutline = gutter.getWhitespaceSeparatorOffset(); + + g.setColor(myDiffType.getIgnoredColor(editor)); + g.fillRect(xOutline, y, x2 - xOutline, height); + + g.setColor(color); + g.fillRect(x1, y, xOutline - x1, height); + } + else { + g.setColor(color); + g.fillRect(x1, y, x2 - x1, height); + } + DiffDrawUtil.drawChunkBorderLine(g2, x1, x2, y - 1, color); + DiffDrawUtil.drawChunkBorderLine(g2, x1, x2, y + height - 1, color); } else { // range is empty - insertion or deletion // Draw 2 pixel line in that case - DiffDrawUtil.drawDoubleChunkBorderLine(g2, x, x + width, y - 1, color); + DiffDrawUtil.drawDoubleChunkBorderLine(g2, x1, x2, y - 1, color); } } }