mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
merge: better range painting for right-only modifications
do not paint in gutter background of middle editor for right-only changes, if there are no line numbers shown
This commit is contained in:
@@ -145,7 +145,8 @@ public class TextMergeChange extends ThreesideDiffChangeBase {
|
||||
int endLine = getEndLine(side);
|
||||
|
||||
boolean ignored = !resolved && myInnerFragments != null;
|
||||
myHighlighters.addAll(DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, ignored, resolved));
|
||||
boolean shouldHideWithoutLineNumbers = side == ThreeSide.BASE && !isChange(Side.LEFT) && isChange(Side.RIGHT);
|
||||
myHighlighters.addAll(DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, ignored, resolved, shouldHideWithoutLineNumbers));
|
||||
myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, startLine, endLine, type, resolved));
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -18,10 +18,7 @@ package com.intellij.diff.tools.simple;
|
||||
import com.intellij.diff.comparison.ComparisonPolicy;
|
||||
import com.intellij.diff.fragments.MergeLineFragment;
|
||||
import com.intellij.diff.fragments.MergeWordFragment;
|
||||
import com.intellij.diff.util.DiffDrawUtil;
|
||||
import com.intellij.diff.util.DiffUtil;
|
||||
import com.intellij.diff.util.TextDiffType;
|
||||
import com.intellij.diff.util.ThreeSide;
|
||||
import com.intellij.diff.util.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
@@ -78,7 +75,8 @@ public class SimpleThreesideDiffChange extends ThreesideDiffChangeBase {
|
||||
|
||||
int start = DiffUtil.getLinesRange(editor.getDocument(), startLine, endLine).getStartOffset();
|
||||
|
||||
myHighlighters.addAll(DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, hasInner));
|
||||
boolean shouldHideWithoutLineNumbers = side == ThreeSide.BASE && !isChange(Side.LEFT) && isChange(Side.RIGHT);
|
||||
myHighlighters.addAll(DiffDrawUtil.createHighlighter(editor, startLine, endLine, type, hasInner, false, shouldHideWithoutLineNumbers));
|
||||
myHighlighters.addAll(DiffDrawUtil.createLineMarker(editor, startLine, endLine, type, false));
|
||||
|
||||
if (hasInner) {
|
||||
|
||||
@@ -210,17 +210,6 @@ public class DiffDrawUtil {
|
||||
};
|
||||
}
|
||||
|
||||
private static void installGutterRenderer(@NotNull RangeHighlighter highlighter,
|
||||
@NotNull TextDiffType type,
|
||||
boolean ignoredFoldingOutline,
|
||||
boolean resolved,
|
||||
boolean isEmptyRange,
|
||||
boolean isLastLine) {
|
||||
DiffLineMarkerRenderer renderer = new DiffLineMarkerRenderer(highlighter, type, ignoredFoldingOutline, resolved,
|
||||
isEmptyRange, isLastLine);
|
||||
highlighter.setLineMarkerRenderer(renderer);
|
||||
}
|
||||
|
||||
private static void installEmptyRangeRenderer(@NotNull RangeHighlighter highlighter,
|
||||
@NotNull TextDiffType type) {
|
||||
highlighter.setCustomRenderer(new DiffEmptyHighlighterRenderer(type));
|
||||
@@ -256,8 +245,9 @@ public class DiffDrawUtil {
|
||||
|
||||
@NotNull
|
||||
public static List<RangeHighlighter> createHighlighter(@NotNull Editor editor, int startLine, int endLine, @NotNull TextDiffType type,
|
||||
boolean ignored, boolean resolved) {
|
||||
return new LineHighlighterBuilder(editor, startLine, endLine, type).withIgnored(ignored).withResolved(resolved).done();
|
||||
boolean ignored, boolean resolved, boolean hideWithoutLineNumbers) {
|
||||
return new LineHighlighterBuilder(editor, startLine, endLine, type).withIgnored(ignored).withResolved(resolved)
|
||||
.withHideWithoutLineNumbers(hideWithoutLineNumbers).done();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -323,6 +313,7 @@ public class DiffDrawUtil {
|
||||
|
||||
private boolean ignored = false;
|
||||
private boolean resolved = false;
|
||||
private boolean hideWithoutLineNumbers = false;
|
||||
|
||||
private LineHighlighterBuilder(@NotNull Editor editor, int startLine, int endLine, @NotNull TextDiffType type) {
|
||||
this.editor = editor;
|
||||
@@ -343,6 +334,11 @@ public class DiffDrawUtil {
|
||||
return this;
|
||||
}
|
||||
|
||||
public LineHighlighterBuilder withHideWithoutLineNumbers(boolean hideWithoutLineNumbers) {
|
||||
this.hideWithoutLineNumbers = hideWithoutLineNumbers;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<RangeHighlighter> done() {
|
||||
boolean isEmptyRange = startLine == endLine;
|
||||
@@ -358,7 +354,8 @@ public class DiffDrawUtil {
|
||||
RangeHighlighter highlighter = editor.getMarkupModel()
|
||||
.addRangeHighlighter(start, end, DEFAULT_LAYER, attributes, HighlighterTargetArea.LINES_IN_RANGE);
|
||||
|
||||
installGutterRenderer(highlighter, type, ignored, resolved, isEmptyRange, isLastLine);
|
||||
highlighter.setLineMarkerRenderer(new DiffLineMarkerRenderer(highlighter, type, ignored, resolved,
|
||||
hideWithoutLineNumbers, isEmptyRange, isLastLine));
|
||||
|
||||
if (stripeAttributes == null) return Collections.singletonList(highlighter);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ public class DiffLineMarkerRenderer implements LineMarkerRendererEx {
|
||||
@NotNull private final TextDiffType myDiffType;
|
||||
private final boolean myIgnoredFoldingOutline;
|
||||
private final boolean myResolved;
|
||||
private final boolean myHideWithoutLineNumbers;
|
||||
|
||||
private final boolean myEmptyRange;
|
||||
private final boolean myLastLine;
|
||||
@@ -37,12 +38,14 @@ public class DiffLineMarkerRenderer implements LineMarkerRendererEx {
|
||||
@NotNull TextDiffType diffType,
|
||||
boolean ignoredFoldingOutline,
|
||||
boolean resolved,
|
||||
boolean hideWithoutLineNumbers,
|
||||
boolean isEmptyRange,
|
||||
boolean isLastLine) {
|
||||
myHighlighter = highlighter;
|
||||
myDiffType = diffType;
|
||||
myIgnoredFoldingOutline = ignoredFoldingOutline;
|
||||
myResolved = resolved;
|
||||
myHideWithoutLineNumbers = hideWithoutLineNumbers;
|
||||
myEmptyRange = isEmptyRange;
|
||||
myLastLine = isLastLine;
|
||||
}
|
||||
@@ -66,11 +69,16 @@ public class DiffLineMarkerRenderer implements LineMarkerRendererEx {
|
||||
height = myEmptyRange ? 0 : DiffDrawUtil.lineToY(editor, endLine) - y;
|
||||
}
|
||||
|
||||
int annotationsOffset = gutter.getAnnotationsAreaOffset();
|
||||
int annotationsWidth = gutter.getAnnotationsAreaWidth();
|
||||
if (annotationsWidth != 0) {
|
||||
drawMarker(editor, g2, x1, annotationsOffset, y, height, false);
|
||||
x1 = annotationsOffset + annotationsWidth;
|
||||
if (myHideWithoutLineNumbers && !editor.getSettings().isLineNumbersShown()) {
|
||||
x1 = gutter.getWhitespaceSeparatorOffset();
|
||||
}
|
||||
else {
|
||||
int annotationsOffset = gutter.getAnnotationsAreaOffset();
|
||||
int annotationsWidth = gutter.getAnnotationsAreaWidth();
|
||||
if (annotationsWidth != 0) {
|
||||
drawMarker(editor, g2, x1, annotationsOffset, y, height, false);
|
||||
x1 = annotationsOffset + annotationsWidth;
|
||||
}
|
||||
}
|
||||
|
||||
if (myIgnoredFoldingOutline) {
|
||||
@@ -85,6 +93,8 @@ public class DiffLineMarkerRenderer implements LineMarkerRendererEx {
|
||||
private void drawMarker(Editor editor, Graphics2D g2,
|
||||
int x1, int x2, int y, int height,
|
||||
boolean ignoredOutline) {
|
||||
if (x1 >= x2) return;
|
||||
|
||||
Color color = myDiffType.getColor(editor);
|
||||
if (height > 2) {
|
||||
if (ignoredOutline) {
|
||||
|
||||
Reference in New Issue
Block a user