diff --git a/platform/diff-impl/src/com/intellij/diff/util/DiffLineSeparatorRenderer.java b/platform/diff-impl/src/com/intellij/diff/util/DiffLineSeparatorRenderer.java index 5766b66d41ef1..f610142c8d90d 100644 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffLineSeparatorRenderer.java +++ b/platform/diff-impl/src/com/intellij/diff/util/DiffLineSeparatorRenderer.java @@ -253,9 +253,9 @@ private static void paintConnectorLine(@NotNull Graphics g, // Parameters // - private static final ColorKey BACKGROUND = ColorKey.createColorKey("DIFF_SEPARATORS_BACKGROUND"); - private static final ColorKey TOP_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_TOP_BORDER"); - private static final ColorKey BOTTOM_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_BOTTOM_BORDER"); + public static final ColorKey BACKGROUND = ColorKey.createColorKey("DIFF_SEPARATORS_BACKGROUND"); + public static final ColorKey TOP_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_TOP_BORDER"); + public static final ColorKey BOTTOM_BORDER = ColorKey.createColorKey("DIFF_SEPARATORS_BOTTOM_BORDER"); private static int getStepSize(int lineHeight) { return Math.max(lineHeight / 3, 1); diff --git a/platform/diff-impl/tests/com/intellij/openapi/diff/impl/settings/DiffColorSettingsTest.kt b/platform/diff-impl/tests/com/intellij/openapi/diff/impl/settings/DiffColorSettingsTest.kt index ad2876e9109dc..d2adace6f190d 100644 --- a/platform/diff-impl/tests/com/intellij/openapi/diff/impl/settings/DiffColorSettingsTest.kt +++ b/platform/diff-impl/tests/com/intellij/openapi/diff/impl/settings/DiffColorSettingsTest.kt @@ -48,6 +48,8 @@ class DiffColorSettingsTest : HeavyDiffTestCase() { assertContainsMarkerColor(viewer, TextDiffType.INSERTED) assertContainsMarkerColor(viewer, TextDiffType.DELETED) assertContainsMarkerColor(viewer, TextDiffType.CONFLICT) + + assertContainsFoldedFragment(viewer) } finally { panel?.disposeUIResources() @@ -82,4 +84,10 @@ class DiffColorSettingsTest : HeavyDiffTestCase() { } assertTrue(ranges.isNotEmpty()) } + + private fun assertContainsFoldedFragment(viewer: SimpleThreesideDiffViewer) { + assertTrue(viewer.editors.all { + it.foldingModel.allFoldRegions.any { !it.isExpanded } + }) + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffColorsPageFactory.java b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffColorsPageFactory.java index cf9a4098fe7f8..619a3e4882023 100644 --- a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffColorsPageFactory.java +++ b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffColorsPageFactory.java @@ -16,8 +16,10 @@ package com.intellij.openapi.diff.impl.settings; import com.intellij.application.options.colors.*; +import com.intellij.diff.util.DiffLineSeparatorRenderer; import com.intellij.diff.util.TextDiffTypeFactory; import com.intellij.openapi.application.ApplicationBundle; +import com.intellij.openapi.options.OptionsBundle; import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorAndFontDescriptorsProvider; import com.intellij.openapi.options.colors.ColorDescriptor; @@ -27,6 +29,7 @@ import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; import java.util.List; public class DiffColorsPageFactory implements ColorAndFontPanelFactory, ColorAndFontDescriptorsProvider, DisplayPrioritySortable { @@ -36,7 +39,11 @@ public class DiffColorsPageFactory implements ColorAndFontPanelFactory, ColorAnd @NotNull public NewColorAndFontPanel createPanel(@NotNull ColorAndFontOptions options) { final SchemesPanel schemesPanel = new SchemesPanel(options); - final DiffColorDescriptionPanel descriptionPanel = new DiffColorDescriptionPanel(options); + + CompositeColorDescriptionPanel descriptionPanel = new CompositeColorDescriptionPanel(); + descriptionPanel.addDescriptionPanel(new ColorAndFontDescriptionPanel(), it -> it instanceof ColorAndFontDescription); + descriptionPanel.addDescriptionPanel(new DiffColorDescriptionPanel(options), it -> it instanceof TextAttributesDescription); + final OptionsPanelImpl optionsPanel = new OptionsPanelImpl(options, schemesPanel, DIFF_GROUP, descriptionPanel); final DiffPreviewPanel previewPanel = new DiffPreviewPanel(); @@ -55,14 +62,22 @@ public void schemeChanged(final Object source) { @Override public AttributesDescriptor[] getAttributeDescriptors() { TextDiffTypeFactory.TextDiffTypeImpl[] diffTypes = TextDiffTypeFactory.getInstance().getAllDiffTypes(); - List attributes = ContainerUtil.map(diffTypes, (type) -> new AttributesDescriptor(type.getName(), type.getKey())); + List attributes = ContainerUtil.map(diffTypes, type -> { + return new AttributesDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.type.tag.prefix") + type.getName(), type.getKey()); + }); return ArrayUtil.toObjectArray(attributes, AttributesDescriptor.class); } @NotNull @Override public ColorDescriptor[] getColorDescriptors() { - return ColorDescriptor.EMPTY_ARRAY; + List descriptors = new ArrayList<>(); + + descriptors.add(new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.separator.background"), DiffLineSeparatorRenderer.BACKGROUND, ColorDescriptor.Kind.BACKGROUND)); + descriptors.add(new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.separator.top_border"), DiffLineSeparatorRenderer.TOP_BORDER, ColorDescriptor.Kind.BACKGROUND)); + descriptors.add(new ColorDescriptor(OptionsBundle.message("options.general.color.descriptor.vcs.diff.separator.bottom_border"), DiffLineSeparatorRenderer.BOTTOM_BORDER, ColorDescriptor.Kind.BACKGROUND)); + + return ArrayUtil.toObjectArray(descriptors, ColorDescriptor.class); } @Override diff --git a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java index 1bf06609b7a90..04790b1a848ff 100644 --- a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java +++ b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewPanel.java @@ -25,14 +25,18 @@ import com.intellij.diff.tools.simple.SimpleThreesideDiffViewer; import com.intellij.diff.tools.util.base.HighlightPolicy; import com.intellij.diff.tools.util.base.IgnorePolicy; +import com.intellij.diff.util.DiffLineSeparatorRenderer; import com.intellij.diff.util.DiffUtil; import com.intellij.diff.util.TextDiffTypeFactory.TextDiffTypeImpl; import com.intellij.diff.util.ThreeSide; import com.intellij.openapi.diff.DiffBundle; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.FoldRegion; import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.editor.colors.EditorColors; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.event.*; +import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.project.Project; @@ -58,17 +62,12 @@ */ class DiffPreviewPanel implements PreviewPanel { private final JPanel myPanel; - private final SimpleThreesideDiffViewer myViewer; + private final MyViewer myViewer; private final EventDispatcher myDispatcher = EventDispatcher.create(ColorAndFontSettingsListener.class); public DiffPreviewPanel() { - myViewer = new SimpleThreesideDiffViewer(new SampleContext(), new SampleRequest()) { - @Override - protected boolean forceRediffSynchronously() { - return true; - } - }; + myViewer = new MyViewer(); myViewer.init(); for (ThreeSide side : ThreeSide.values()) { @@ -94,11 +93,14 @@ public void updateView() { for (SimpleThreesideDiffChange change : changes) { change.reinstallHighlighters(); } + myViewer.repaint(); } public void setColorScheme(final EditorColorsScheme highlighterSettings) { for (EditorEx editorEx : myViewer.getEditors()) { - editorEx.setColorsScheme(highlighterSettings); + editorEx.setColorsScheme(editorEx.createBoundColorSchemeDelegate(highlighterSettings)); + editorEx.getColorsScheme().setAttributes(EditorColors.FOLDED_TEXT_ATTRIBUTES, null); + editorEx.reinitSettings(); } } @@ -133,6 +135,8 @@ public SampleContext() { TextDiffSettings settings = new TextDiffSettings(); settings.setHighlightPolicy(HighlightPolicy.BY_WORD); settings.setIgnorePolicy(IgnorePolicy.IGNORE_WHITESPACES); + settings.setContextRange(2); + settings.setExpandByDefault(false); putUserData(TextDiffSettings.KEY, settings); } @@ -171,7 +175,10 @@ private EditorMouseListener(@NotNull ThreeSide side) { @Override public void mouseMoved(EditorMouseEvent e) { - if (getChange(mySide, e) != null) EditorUtil.setHandCursor(e.getEditor()); + int line = getLineNumber(mySide, e); + if (getChange(mySide, line) != null || getFoldRegion(mySide, line) != null) { + EditorUtil.setHandCursor(e.getEditor()); + } } } @@ -184,34 +191,41 @@ private EditorClickListener(@NotNull ThreeSide side) { @Override public void mouseClicked(EditorMouseEvent e) { - selectChange(getChange(mySide, e)); + selectColorForLine(mySide, getLineNumber(mySide, e)); } @Override public void caretPositionChanged(CaretEvent e) { - selectChange(getChange(mySide, e.getNewPosition().line)); + selectColorForLine(mySide, e.getNewPosition().line); } } - private void selectChange(@Nullable SimpleThreesideDiffChange change) { - if (change == null) return; - TextDiffTypeImpl diffType = ObjectUtils.tryCast(change.getDiffType(), TextDiffTypeImpl.class); - if (diffType != null) { - myDispatcher.getMulticaster().selectionInPreviewChanged(diffType.getKey().getExternalName()); + private void selectColorForLine(@NotNull ThreeSide side, int line) { + SimpleThreesideDiffChange change = getChange(side, line); + if (change != null) { + TextDiffTypeImpl diffType = ObjectUtils.tryCast(change.getDiffType(), TextDiffTypeImpl.class); + if (diffType != null) { + myDispatcher.getMulticaster().selectionInPreviewChanged(diffType.getKey().getExternalName()); + } + return; + } + + FoldRegion region = getFoldRegion(side, line); + if (region != null) { + myDispatcher.getMulticaster().selectionInPreviewChanged(DiffLineSeparatorRenderer.BACKGROUND.getExternalName()); + return; } } - @Nullable - private SimpleThreesideDiffChange getChange(ThreeSide side, EditorMouseEvent e) { + private int getLineNumber(@NotNull ThreeSide side, EditorMouseEvent e) { EditorEx editor = myViewer.getEditor(side); LogicalPosition logicalPosition = editor.xyToLogicalPosition(e.getMouseEvent().getPoint()); int offset = editor.logicalPositionToOffset(logicalPosition); - int line = editor.getDocument().getLineNumber(offset); - return getChange(side, line); + return editor.getDocument().getLineNumber(offset); } @Nullable - private SimpleThreesideDiffChange getChange(ThreeSide side, int line) { + private SimpleThreesideDiffChange getChange(@NotNull ThreeSide side, int line) { for (SimpleThreesideDiffChange change : myViewer.getChanges()) { int startLine = change.getStartLine(side); int endLine = change.getEndLine(side); @@ -220,6 +234,19 @@ private SimpleThreesideDiffChange getChange(ThreeSide side, int line) { return null; } + @Nullable + private FoldRegion getFoldRegion(@NotNull ThreeSide side, int line) { + EditorEx editor = myViewer.getEditor(side); + DocumentEx document = editor.getDocument(); + for (FoldRegion region : editor.getFoldingModel().getAllFoldRegions()) { + if (region.isExpanded()) continue; + int line1 = document.getLineNumber(region.getStartOffset()); + int line2 = document.getLineNumber(region.getEndOffset()); + if (line1 <= line && line <= line2) return region; + } + return null; + } + @Override public void blinkSelectedHighlightType(final Object selected) { } @@ -234,4 +261,17 @@ public void disposeUIResources() { public SimpleThreesideDiffViewer testGetViewer() { return myViewer; } + + private static class MyViewer extends SimpleThreesideDiffViewer { + public MyViewer() {super(new SampleContext(), new SampleRequest());} + + @Override + protected boolean forceRediffSynchronously() { + return true; + } + + public void repaint() { + myPanel.repaint(); + } + } } diff --git a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewProvider.java b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewProvider.java index f1fe07b82d07b..57d494fd6ae45 100644 --- a/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewProvider.java +++ b/platform/lang-impl/src/com/intellij/openapi/diff/impl/settings/DiffPreviewProvider.java @@ -73,7 +73,9 @@ private static DiffContent createContent(@NotNull String text, @NotNull FileType " void bar() {\n" + "\n" + " }\n" + - "}"; + "}\n" + + "\n" + + "\n"; @NonNls private static final String CENTER_TEXT = "class MyClass {\n" + " int value;\n" + "\n" + @@ -85,7 +87,9 @@ private static DiffContent createContent(@NotNull String text, @NotNull FileType " void bar() {\n" + "\n" + " }\n" + - "}"; + "}\n" + + "\n" + + "\n"; @NonNls private static final String RIGHT_TEXT = "class MyClass {\n" + " long value;\n" + "\n" + @@ -98,5 +102,7 @@ private static DiffContent createContent(@NotNull String text, @NotNull FileType " void bar() {\n" + " }\n" + "\n" + - "}"; + "}\n" + + "\n" + + "\n"; } diff --git a/platform/platform-resources-en/src/messages/OptionsBundle.properties b/platform/platform-resources-en/src/messages/OptionsBundle.properties index 714aa9f02ebeb..42eee2d37dea4 100644 --- a/platform/platform-resources-en/src/messages/OptionsBundle.properties +++ b/platform/platform-resources-en/src/messages/OptionsBundle.properties @@ -141,6 +141,10 @@ options.general.color.descriptor.vcs.log.refs.leaf=VCS Log//Common//Leaf options.general.color.descriptor.vcs.log.refs.branch=VCS Log//Common//Branch options.general.color.descriptor.vcs.log.refs.branch.tag=VCS Log//Common//Branch tag options.general.color.descriptor.vcs.log.refs.tag=VCS Log//Common//Tag +options.general.color.descriptor.vcs.diff.type.tag.prefix=Changed lines// +options.general.color.descriptor.vcs.diff.separator.background=Folded unchanged fragments//Background +options.general.color.descriptor.vcs.diff.separator.top_border=Folded unchanged fragments//Top border +options.general.color.descriptor.vcs.diff.separator.bottom_border=Folded unchanged fragments//Bottom border options.general.color.descriptor.tearline=Editor//Tear line options.general.color.descriptor.tearline.selected=Editor//Tear line selection options.general.color.descriptor.separator.above=Editor//Separator line above diff --git a/python/python-community-configure/src/com/jetbrains/python/configuration/PyDiffPreviewProvider.java b/python/python-community-configure/src/com/jetbrains/python/configuration/PyDiffPreviewProvider.java index 3447a4f2a691a..dc7e3bc2bcaf6 100644 --- a/python/python-community-configure/src/com/jetbrains/python/configuration/PyDiffPreviewProvider.java +++ b/python/python-community-configure/src/com/jetbrains/python/configuration/PyDiffPreviewProvider.java @@ -44,7 +44,10 @@ public DiffContent[] createContents() { " def bar(self, a, b)\n" + "\n" + " print a\n" + - " print b"; + " print b\n" + + "\n" + + "\n" + + "\n"; @NonNls private static final String CENTER_TEXT = "class MyClass\n" + " value = 123\n" + "\n" + @@ -57,7 +60,10 @@ public DiffContent[] createContents() { " def bar(self, a, b)\n" + "\n" + " print a\n" + - " print b"; + " print b\n" + + "\n" + + "\n" + + "\n"; @NonNls private static final String RIGHT_TEXT = "class MyClass\n" + " value = -123\n" + "\n" + @@ -71,5 +77,8 @@ public DiffContent[] createContents() { " def bar(self, a, b)\n" + " print a\n" + "\n" + - " print b"; + " print b\n" + + "\n" + + "\n" + + "\n"; }