diff: add editor painting tests
GitOrigin-RevId: 9b6f6fdce791666c4ce5b11ab391a087cb81ff5d
@@ -3,6 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$/tests">
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests/testData" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests/testSrc" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
@@ -17,5 +18,6 @@
|
||||
<orderEntry type="library" scope="TEST" name="mockito" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.vcs.impl" scope="TEST" />
|
||||
<orderEntry type="module" module-name="intellij.platform.tests" scope="TEST" />
|
||||
</component>
|
||||
</module>
|
||||
|
After Width: | Height: | Size: 357 B |
|
After Width: | Height: | Size: 295 B |
|
After Width: | Height: | Size: 183 B |
|
After Width: | Height: | Size: 342 B |
|
After Width: | Height: | Size: 235 B |
|
After Width: | Height: | Size: 259 B |
|
After Width: | Height: | Size: 309 B |
|
After Width: | Height: | Size: 351 B |
|
After Width: | Height: | Size: 249 B |
|
After Width: | Height: | Size: 175 B |
|
After Width: | Height: | Size: 165 B |
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 286 B |
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||