diff options
| author | Mickael Istria | 2021-01-12 20:54:42 +0000 |
|---|---|---|
| committer | Mickael Istria | 2021-01-13 06:53:59 +0000 |
| commit | da8340bb75569958e631ae94641994c1804c8d69 (patch) | |
| tree | 3037cebe1d06335598d6b10605b06b41ac8d72a8 | |
| parent | 645c638ddcde81a58c78a25f5952ca043201ab1e (diff) | |
| download | eclipse.platform.swt-da8340bb75569958e631ae94641994c1804c8d69.tar.gz eclipse.platform.swt-da8340bb75569958e631ae94641994c1804c8d69.tar.xz eclipse.platform.swt-da8340bb75569958e631ae94641994c1804c8d69.zip | |
Bug 570208 - Rendering/Scroll issue with vertical indent (cont'd)
Change-Id: I198c22a56c3f68a41ba6fa0e0c3b51177e58a942
Signed-off-by: Mickael Istria <mistria@redhat.com>
3 files changed, 38 insertions, 7 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index e6b827f407..b11cc92f02 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -9453,13 +9453,19 @@ public void setLineVerticalIndent(int lineIndex, int verticalLineIndent) { int verticalIndentDiff = verticalLineIndent - previousVerticalIndent; renderer.setLineVerticalIndent(lineIndex, verticalLineIndent); this.hasVerticalIndent = verticalLineIndent != 0 || renderer.hasVerticalIndent(); - resetCache(lineIndex, 1); + ScrollBar verticalScrollbar = getVerticalBar(); if (lineIndex < initialTopIndex) { verticalScrollOffset += verticalIndentDiff; // just change value, don't actually scroll/redraw - setScrollBars(true); + if (verticalScrollbar != null) { + verticalScrollbar.setSelection(verticalScrollOffset); + verticalScrollbar.setMaximum(verticalScrollbar.getMaximum() + verticalIndentDiff); + } } else if (lineIndex > initialBottomIndex) { - setScrollBars(true); + if (verticalScrollbar != null) { + verticalScrollbar.setMaximum(verticalScrollbar.getMaximum() + verticalIndentDiff); + } } else { + resetCache(lineIndex, 1); if (getCaretLine() >= initialTopIndex && getCaretLine() <= initialBottomIndex) { // caret line with caret mustn't move if (getCaretLine() < lineIndex) { redrawLines(lineIndex, getPartialBottomIndex() - lineIndex + 1, true); diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java index 7a9d8de766..67dea5b665 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java @@ -675,7 +675,7 @@ int getLineHeight(int lineIndex, boolean exact) { return Math.round(averageLineHeight); } } else { - line.height = getLineHeight() + getLineSpacing(lineIndex); + line.height = getLineHeight() + getLineSpacing(lineIndex) + getLineVerticalIndent(lineIndex); } } return line.height; @@ -1476,7 +1476,12 @@ void setLineVerticalIndent(int lineIndex, int verticalLineIndent) { lines[lineIndex] = new LineInfo(); } lines[lineIndex].flags |= VERTICAL_INDENT; + int delta = verticalLineIndent - lines[lineIndex].verticalIndent; lines[lineIndex].verticalIndent = verticalLineIndent; + LineSizeInfo info = getLineSize(lineIndex); + if (!info.needsRecalculateHeight()) { + info.height += delta; + } } void setLineWrapIndent(int startLine, int count, int wrapIndent) { if (lines == null) lines = new LineInfo[lineCount]; diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java index 0e4a1b1222..3d8c82ae87 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java @@ -71,6 +71,7 @@ import org.eclipse.swt.printing.Printer; import org.eclipse.swt.widgets.Caret; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Widget; import org.eclipse.test.Screenshots; import org.junit.After; @@ -4925,7 +4926,10 @@ public void test_verticalIndent_changeRelativeBounds() { } @Test -public void test_verticalIndent_keepsCurrentCaretAndLinePosition() { +public void test_verticalIndent_keepsCurrentCaretAndLinePosition() throws InterruptedException { + text.dispose(); + text = new StyledText(shell, SWT.V_SCROLL); + setWidget(text); String _50lines = IntStream.range(1, 50).mapToObj(Integer::toString).collect(Collectors.joining("\n")); text.setText(_50lines); text.setSize(500, 200); @@ -4941,28 +4945,44 @@ public void test_verticalIndent_keepsCurrentCaretAndLinePosition() { int initialTopPixel = text.getTopPixel(); Point caretLocation = text.getCaret().getLocation(); Point offsetLocation = text.getLocationAtOffset(offset); + ScrollBar scrollbar = text.getVerticalBar(); + int scrollMini = scrollbar.getMinimum(); + int scrollMaxi = scrollbar.getMaximum(); + int scrollOffset = scrollbar.getSelection(); // on active line text.setLineVerticalIndent(line, INDENT); assertEquals(caretLocation, text.getCaret().getLocation()); assertEquals(offsetLocation, text.getLocationAtOffset(offset)); assertEquals("vertical scroll should have been updated", initialTopPixel + INDENT, text.getTopPixel()); + assertEquals(scrollMini, scrollbar.getMinimum()); + assertEquals(scrollMaxi + INDENT, scrollbar.getMaximum()); + assertEquals(scrollOffset + INDENT, scrollbar.getSelection()); text.setLineVerticalIndent(line, 0); assertEquals(caretLocation, text.getCaret().getLocation()); assertEquals(offsetLocation, text.getLocationAtOffset(offset)); assertEquals("vertical scroll should have been restored", initialTopPixel, text.getTopPixel()); + assertEquals(scrollMini, scrollbar.getMinimum()); + assertEquals(scrollMaxi, scrollbar.getMaximum()); + assertEquals(scrollOffset, scrollbar.getSelection()); // above visible area - //render(shell, 5000); + render(shell, 5000); text.setLineVerticalIndent(0, INDENT); - //render(shell, 5000); + render(shell, 5000); assertEquals(caretLocation, text.getCaret().getLocation()); assertEquals(offsetLocation, text.getLocationAtOffset(offset)); assertEquals("vertical scroll should have been updated", initialTopPixel + INDENT, text.getTopPixel()); + assertEquals(scrollMini, scrollbar.getMinimum()); + assertEquals(scrollMaxi + INDENT, scrollbar.getMaximum()); + assertEquals(scrollOffset + INDENT, scrollbar.getSelection()); text.setLineVerticalIndent(0, 0); assertEquals(caretLocation, text.getCaret().getLocation()); assertEquals(offsetLocation, text.getLocationAtOffset(offset)); assertEquals("vertical scroll should have been updated", initialTopPixel, text.getTopPixel()); + assertEquals(scrollMini, scrollbar.getMinimum()); + assertEquals(scrollMaxi, scrollbar.getMaximum()); + assertEquals(scrollOffset, scrollbar.getSelection()); //below visible area int nextInvisibleLine = text.getLineIndex(text.getClientArea().height - 1) + 1; |
