diff --git a/platform/diff-impl/intellij.platform.diff.tests.iml b/platform/diff-impl/intellij.platform.diff.tests.iml index 60a966d6d9e7..de9d7ca33a89 100644 --- a/platform/diff-impl/intellij.platform.diff.tests.iml +++ b/platform/diff-impl/intellij.platform.diff.tests.iml @@ -3,6 +3,7 @@ + @@ -17,5 +18,6 @@ + \ No newline at end of file diff --git a/platform/diff-impl/tests/testData/diff/painting/borderLineMarker.png b/platform/diff-impl/tests/testData/diff/painting/borderLineMarker.png new file mode 100644 index 000000000000..b3fbf769502a Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/borderLineMarker.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/emptyRange.png b/platform/diff-impl/tests/testData/diff/painting/emptyRange.png new file mode 100644 index 000000000000..18ea45c53ad2 Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/emptyRange.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastEmptyLine.png b/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastEmptyLine.png new file mode 100644 index 000000000000..32178299d554 Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastEmptyLine.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastLineSoftWraps.png b/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastLineSoftWraps.png new file mode 100644 index 000000000000..d68230c5285a Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/emptyRangeLastLineSoftWraps.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/lastEmptyLineChanged.png b/platform/diff-impl/tests/testData/diff/painting/lastEmptyLineChanged.png new file mode 100644 index 000000000000..3a2f27a8a8a4 Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/lastEmptyLineChanged.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/lastLineChanged.png b/platform/diff-impl/tests/testData/diff/painting/lastLineChanged.png new file mode 100644 index 000000000000..ec7c54b5d696 Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/lastLineChanged.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/lastLineSoftWraps.png b/platform/diff-impl/tests/testData/diff/painting/lastLineSoftWraps.png new file mode 100644 index 000000000000..e2d2e07998c1 Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/lastLineSoftWraps.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/lineMarker.png b/platform/diff-impl/tests/testData/diff/painting/lineMarker.png new file mode 100644 index 000000000000..d9253b610934 Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/lineMarker.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/newlineChanged.png b/platform/diff-impl/tests/testData/diff/painting/newlineChanged.png new file mode 100644 index 000000000000..999df9beb40d Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/newlineChanged.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/oneLetterChanged.png b/platform/diff-impl/tests/testData/diff/painting/oneLetterChanged.png new file mode 100644 index 000000000000..9b24cf2a9abd Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/oneLetterChanged.png differ diff --git a/platform/diff-impl/tests/testData/diff/painting/wholeLineChanged.png b/platform/diff-impl/tests/testData/diff/painting/wholeLineChanged.png new file mode 100644 index 000000000000..45ad794e17ec Binary files /dev/null and b/platform/diff-impl/tests/testData/diff/painting/wholeLineChanged.png differ diff --git a/platform/diff-impl/tests/testSrc/com/intellij/diff/painting/DiffEditorPaintingTest.kt b/platform/diff-impl/tests/testSrc/com/intellij/diff/painting/DiffEditorPaintingTest.kt new file mode 100644 index 000000000000..77a02be769c9 --- /dev/null +++ b/platform/diff-impl/tests/testSrc/com/intellij/diff/painting/DiffEditorPaintingTest.kt @@ -0,0 +1,100 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.diff.painting + +import com.intellij.diff.util.DiffDrawUtil +import com.intellij.diff.util.TextDiffType +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.editor.EditorPaintingTestCase +import com.intellij.openapi.editor.markup.SeparatorPlacement +import com.intellij.testFramework.TestDataPath +import java.awt.Color + +@TestDataPath("\$CONTENT_ROOT/testData/diff/painting") +class DiffEditorPaintingTest : EditorPaintingTestCase() { + override fun getTestDataPath(): String { + return "platform/diff-impl/tests/testData/diff/painting" + } + + fun testWholeLineChanged() { + initText("foo") + DiffDrawUtil.createHighlighter(myEditor, 0, 1, MyDiffType, false) + checkResultWithGutter() + } + + fun testOneLetterChanged() { + initText("foo") + DiffDrawUtil.createHighlighter(myEditor, 0, 1, MyDiffType, true) + DiffDrawUtil.createInlineHighlighter(myEditor, 1, 2, MyDiffType) + checkResultWithGutter() + } + + fun testNewlineChanged() { + initText("fo\nbar") + DiffDrawUtil.createHighlighter(myEditor, 0, 2, MyDiffType, true) + DiffDrawUtil.createInlineHighlighter(myEditor, 2, 3, MyDiffType) + checkResultWithGutter() + } + + fun testLastLineChanged() { + initText("foo\nx") + DiffDrawUtil.createHighlighter(myEditor, 1, 2, MyDiffType, false) + checkResultWithGutter() + } + + fun testLastEmptyLineChanged() { + initText("foo\n") + DiffDrawUtil.createHighlighter(myEditor, 1, 2, MyDiffType, false) + checkResultWithGutter() + } + + fun testLastLineSoftWraps() { + initText("foo ba biz") + configureSoftWraps(4); + DiffDrawUtil.createHighlighter(myEditor, 0, 1, MyDiffType, false) + checkResultWithGutter() + } + + fun testEmptyRange() { + initText("foo\nbar") + DiffDrawUtil.createHighlighter(myEditor, 1, 1, MyDiffType, false) + checkResultWithGutter() + } + + fun testEmptyRangeLastEmptyLine() { + initText("foo") + DiffDrawUtil.createHighlighter(myEditor, 1, 1, MyDiffType, false) + checkResultWithGutter() + } + + fun testEmptyRangeLastLineSoftWraps() { + initText("foo ba biz") + configureSoftWraps(4); + DiffDrawUtil.createHighlighter(myEditor, 1, 1, MyDiffType, false) + checkResultWithGutter() + } + + fun testLineMarker() { + initText("fo o\nba r") + configureSoftWraps(2); + + DiffDrawUtil.createLineMarker(myEditor, 1, MyDiffType) + checkResultWithGutter() + } + + fun testBorderLineMarker() { + initText("fo o\nba r") + configureSoftWraps(2); + + DiffDrawUtil.createBorderLineMarker(myEditor, 1, SeparatorPlacement.BOTTOM) + DiffDrawUtil.createBorderLineMarker(myEditor, 1, SeparatorPlacement.TOP) + checkResultWithGutter() + } + + private object MyDiffType : TextDiffType { + override fun getName(): String = throw UnsupportedOperationException() + override fun getColor(editor: Editor?): Color = Color.RED + override fun getIgnoredColor(editor: Editor?): Color = Color.BLUE + override fun getMarkerColor(editor: Editor?): Color? = Color.GREEN + } +} + diff --git a/platform/platform-tests/testData/editor/painting/softWrapWithWithLineSeparator.png b/platform/platform-tests/testData/editor/painting/softWrapWithWithLineSeparator.png new file mode 100644 index 000000000000..79e4f2799d0b Binary files /dev/null and b/platform/platform-tests/testData/editor/painting/softWrapWithWithLineSeparator.png differ diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java index 80b1051800be..a97093a40a94 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTest.java @@ -21,9 +21,7 @@ import com.intellij.openapi.editor.event.DocumentEvent; import com.intellij.openapi.editor.event.DocumentListener; import com.intellij.openapi.editor.ex.DocumentEx; import com.intellij.openapi.editor.ex.EditorEx; -import com.intellij.openapi.editor.markup.EffectType; -import com.intellij.openapi.editor.markup.HighlighterLayer; -import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.editor.markup.*; import com.intellij.testFramework.TestDataPath; import org.jetbrains.annotations.NotNull; @@ -135,4 +133,20 @@ public class EditorPaintingTest extends EditorPaintingTestCase { WriteCommandAction.runWriteCommandAction(ourProject, () -> ((DocumentEx)myEditor.getDocument()).moveText(5, 10, 0)); checkResult(); } + + public void testSoftWrapWithWithLineSeparator() throws Exception { + initText("x\nabcef\ny"); + configureSoftWraps(2); + verifySoftWrapPositions(4, 5); + + RangeHighlighter topHighlighter = addRangeHighlighter(4, 4, 0, null); + topHighlighter.setLineSeparatorColor(Color.red); + topHighlighter.setLineSeparatorPlacement(SeparatorPlacement.TOP); + + RangeHighlighter bottomHighlighter = addRangeHighlighter(4, 4, 0, null); + bottomHighlighter.setLineSeparatorColor(Color.blue); + bottomHighlighter.setLineSeparatorPlacement(SeparatorPlacement.BOTTOM); + + checkResult(); + } } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java index 40e4759cc579..ff1ac87e8bea 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorPaintingTestCase.java @@ -21,12 +21,14 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.HighlighterClient; import com.intellij.openapi.editor.highlighter.HighlighterIterator; import com.intellij.openapi.editor.impl.AbstractEditorTest; +import com.intellij.openapi.editor.impl.EditorImpl; import com.intellij.openapi.editor.impl.SoftWrapModelImpl; import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType; import com.intellij.openapi.editor.impl.softwrap.SoftWrapPainter; import com.intellij.openapi.editor.impl.view.FontLayoutService; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.HighlighterTargetArea; +import com.intellij.openapi.editor.markup.RangeHighlighter; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.tree.IElementType; @@ -69,7 +71,11 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { } protected void checkResult() throws IOException { - checkResult(getFileName()); + checkResult(getFileName(), false); + } + + protected void checkResultWithGutter() throws IOException { + checkResult(getFileName(), true); } @NotNull @@ -81,24 +87,24 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { ((EditorEx)myEditor).setHighlighter(new UniformHighlighter(attributes)); } - protected static void addRangeHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { - addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); + protected static RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { + return addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); } - protected static void addLineHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { - addLineHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); + protected static RangeHighlighter addLineHighlighter(int startOffset, int endOffset, int layer, Color foregroundColor, Color backgroundColor) { + return addLineHighlighter(startOffset, endOffset, layer, new TextAttributes(foregroundColor, backgroundColor, null, null, Font.PLAIN)); } - protected static void addRangeHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { - myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.EXACT_RANGE); + protected static RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { + return myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.EXACT_RANGE); } - protected static void addLineHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { - myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); + protected static RangeHighlighter addLineHighlighter(int startOffset, int endOffset, int layer, TextAttributes textAttributes) { + return myEditor.getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, textAttributes, HighlighterTargetArea.LINES_IN_RANGE); } - protected static void addBorderHighlighter(int startOffset, int endOffset, int layer, Color borderColor) { - addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(null, null, borderColor, EffectType.BOXED, Font.PLAIN)); + protected static RangeHighlighter addBorderHighlighter(int startOffset, int endOffset, int layer, Color borderColor) { + return addRangeHighlighter(startOffset, endOffset, layer, new TextAttributes(null, null, borderColor, EffectType.BOXED, Font.PLAIN)); } @Override @@ -165,18 +171,29 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { return TEST_DATA_PATH; } - private void checkResult(@TestDataFile String expectedResultFileName) throws IOException { + private void checkResult(@TestDataFile String expectedResultFileName, boolean withGutter) throws IOException { myEditor.getSettings().setAdditionalLinesCount(0); myEditor.getSettings().setAdditionalColumnsCount(1); + JComponent editorComponent = myEditor.getContentComponent(); - Dimension size = editorComponent.getPreferredSize(); - editorComponent.setSize(size); + JComponent gutterComponent = withGutter ? ((EditorImpl)myEditor).getGutterComponentEx() : new MyEmptyPanel(); + + Dimension editorSize = editorComponent.getPreferredSize(); + Dimension gutterSize = gutterComponent.getPreferredSize(); + Dimension imageSize = new Dimension(editorSize.width + gutterSize.width, Math.max(editorSize.height, gutterSize.height)); + + editorComponent.setSize(editorSize.width, imageSize.height); + gutterComponent.setSize(gutterSize.width, imageSize.height); + //noinspection UndesirableClassUsage - BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); + BufferedImage image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_INT_ARGB); BitmapFont plainFont = BitmapFont.loadFromFile(getFontFile(false)); BitmapFont boldFont = BitmapFont.loadFromFile(getFontFile(true)); MyGraphics graphics = new MyGraphics(image.createGraphics(), plainFont, boldFont); try { + gutterComponent.paint(graphics); + graphics.translate(gutterComponent.getWidth(), 0); + editorComponent.paint(graphics); } finally { @@ -258,6 +275,11 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { } } + @Override + public void drawString(String str, int x, int y) { + drawString(str, (float)x, (float)y); + } + private void drawChar(char c, int x, int y) { (((getFont().getStyle() & Font.BOLD) == 0) ? myPlainFont : myBoldFont).draw(myDelegate, c, x, y); } @@ -409,4 +431,11 @@ public abstract class EditorPaintingTestCase extends AbstractEditorTest { BitmapFont boldBont = BitmapFont.createFromFont(font.deriveFont(Font.BOLD)); boldBont.saveToFile(getFontFile(true)); } + + private static class MyEmptyPanel extends JComponent { + @Override + public Dimension getPreferredSize() { + return new Dimension(0, 0); + } + } }