IDEA-141276 diff: show wide stripe markers

we have to create separate highlighter for line markers to show error stripes over diff stripes
This commit is contained in:
Aleksey Pivovarov
2015-07-15 20:30:52 +03:00
parent 956acd4625
commit 591db8a785
7 changed files with 77 additions and 69 deletions
@@ -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() {
@@ -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) {
@@ -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));
}
}
@@ -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));
}
}
@@ -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)));
}
}
@@ -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<RangeHighlighter> 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<RangeHighlighter> 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<RangeHighlighter> 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<RangeHighlighter> 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<RangeHighlighter> 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<RangeHighlighter> 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<RangeHighlighter> 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<RangeHighlighter> 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<RangeHighlighter> 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);
}
}
@@ -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() {