Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2021-01-11 10:54:24 +0000
committerMickael Istria2021-01-11 20:32:46 +0000
commit44d171c4d147e7c175dcc3a3fdea966dc7c5de44 (patch)
tree4bd258ace1c6778d8656a4c1c84fa969bb38a315
parent4439b0b00f2fc82135880d7afe1ef9a451332c91 (diff)
downloadeclipse.platform.swt-44d171c4d147e7c175dcc3a3fdea966dc7c5de44.tar.gz
eclipse.platform.swt-44d171c4d147e7c175dcc3a3fdea966dc7c5de44.tar.xz
eclipse.platform.swt-44d171c4d147e7c175dcc3a3fdea966dc7c5de44.zip
Bug 570208 - Rendering/Scroll issue with vertical indent
Change-Id: I291c0a242a17b3ec76d13b7a061ddcd3d0775383 Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java10
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java26
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java20
3 files changed, 47 insertions, 9 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 986c4fc54d..e6b827f407 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
@@ -9449,15 +9449,18 @@ public void setLineVerticalIndent(int lineIndex, int verticalLineIndent) {
}
int initialTopPixel = getTopPixel();
int initialTopIndex = getPartialTopIndex();
- int initialBottonIndex = getPartialBottomIndex();
+ int initialBottomIndex = getPartialBottomIndex();
int verticalIndentDiff = verticalLineIndent - previousVerticalIndent;
renderer.setLineVerticalIndent(lineIndex, verticalLineIndent);
this.hasVerticalIndent = verticalLineIndent != 0 || renderer.hasVerticalIndent();
resetCache(lineIndex, 1);
- if (lineIndex < initialTopIndex || lineIndex > getPartialBottomIndex()) {
+ if (lineIndex < initialTopIndex) {
+ verticalScrollOffset += verticalIndentDiff; // just change value, don't actually scroll/redraw
+ setScrollBars(true);
+ } else if (lineIndex > initialBottomIndex) {
setScrollBars(true);
} else {
- if (getCaretLine() >= initialTopIndex && getCaretLine() <= initialBottonIndex) { // caret line with caret mustn't move
+ if (getCaretLine() >= initialTopIndex && getCaretLine() <= initialBottomIndex) { // caret line with caret mustn't move
if (getCaretLine() < lineIndex) {
redrawLines(lineIndex, getPartialBottomIndex() - lineIndex + 1, true);
} else {
@@ -9471,6 +9474,7 @@ public void setLineVerticalIndent(int lineIndex, int verticalLineIndent) {
redrawLines(lineIndex, getPartialBottomIndex() - lineIndex + 1, true);
}
}
+ setScrollBars(true);
}
}
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 c9c3994a2a..6706c94458 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
@@ -4925,10 +4925,11 @@ public void test_verticalIndent_changeRelativeBounds() {
}
@Test
-public void test_verticalIndent_keepsCurrentCaretAndLinePosition() throws InterruptedException {
+public void test_verticalIndent_keepsCurrentCaretAndLinePosition() {
String _50lines = IntStream.range(1, 50).mapToObj(Integer::toString).collect(Collectors.joining("\n"));
text.setText(_50lines);
text.setSize(500, 200);
+ final int INDENT = 34;
int line = 30;
int offset = text.getOffsetAtLine(line);
text.setSelection(offset);
@@ -4937,49 +4938,62 @@ public void test_verticalIndent_keepsCurrentCaretAndLinePosition() throws Interr
line = text.getLineIndex(text.getClientArea().height / 2);
offset = text.getOffsetAtLine(line);
text.setSelection(offset);
+ int initialTopPixel = text.getTopPixel();
Point caretLocation = text.getCaret().getLocation();
Point offsetLocation = text.getLocationAtOffset(offset);
// on active line
- text.setLineVerticalIndent(line, 34);
+ 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());
text.setLineVerticalIndent(line, 0);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("vertical scroll should have been restored", initialTopPixel, text.getTopPixel());
// above visible area
- text.setLineVerticalIndent(0, 34);
+ //render(shell, 5000);
+ text.setLineVerticalIndent(0, INDENT);
+ //render(shell, 5000);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("vertical scroll should have been updated", initialTopPixel + INDENT, text.getTopPixel());
text.setLineVerticalIndent(0, 0);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("vertical scroll should have been updated", initialTopPixel, text.getTopPixel());
//below visible area
int nextInvisibleLine = text.getLineIndex(text.getClientArea().height - 1) + 1;
- text.setLineVerticalIndent(nextInvisibleLine, 34);
+ text.setLineVerticalIndent(nextInvisibleLine, INDENT);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("Vertical scroll shouldn't be modified",initialTopPixel, text.getTopPixel());
text.setLineVerticalIndent(nextInvisibleLine, 0);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("Vertical scroll shouldn't be modified",initialTopPixel, text.getTopPixel());
// above active line, in visible area
- text.setLineVerticalIndent(line - 2, 34);
+ text.setLineVerticalIndent(line - 2, INDENT);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("Vertical scroll should have been updated",initialTopPixel + INDENT, text.getTopPixel());
text.setLineVerticalIndent(line - 2, 0);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("Vertical scroll should have been restored",initialTopPixel, text.getTopPixel());
// below active line, in visible area
- text.setLineVerticalIndent(line + 2, 34);
+ text.setLineVerticalIndent(line + 2, INDENT);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("Vertical scroll shouldn't be modified",initialTopPixel, text.getTopPixel());
text.setLineVerticalIndent(line + 2, 0);
assertEquals(caretLocation, text.getCaret().getLocation());
assertEquals(offsetLocation, text.getLocationAtOffset(offset));
+ assertEquals("Vertical scroll shouldn't be modified",initialTopPixel, text.getTopPixel());
}
@Test
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java
index 8fdcaad62f..9dcab165c3 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Widget.java
@@ -251,6 +251,26 @@ protected void processEvents(int timeoutMs, BooleanSupplier breakCondition) thro
}
}
+/**
+ * Renders the shell and process events for duration.
+ * Convenience method for debugging tests, ⚠️ should not be
+ * called for headless tests!
+ * @param shell The shell to render.
+ * @param durationMs duration in milliseconds. Method exits after duration.
+ * @throws InterruptedException
+ */
+protected void render(Shell shell, int durationMs) throws InterruptedException {
+ long timestamp = System.currentTimeMillis();
+ shell.pack();
+ shell.layout();
+ shell.setVisible(true);
+ while (System.currentTimeMillis() - timestamp < durationMs) {
+ if (!shell.getDisplay().readAndDispatch()) {
+ Thread.sleep(50);
+ }
+ }
+}
+
protected void assertNotExists(Widget[] widgetTable, Widget w) {
for (Widget widget : widgetTable) {
if(widget == w) {

Back to the top