IDEA-135671 diff: better painting in gutter

Paint half of folding outline in gutter like it is a part of editor
This commit is contained in:
Aleksey Pivovarov
2015-04-02 18:33:26 +03:00
parent 8fee2e3fb9
commit a32b8f4aad
2 changed files with 36 additions and 11 deletions
@@ -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) {
@@ -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);
}
}
}