Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2019-08-14 07:13:18 +0000
committerAndrey Loskutov2019-08-14 14:03:23 +0000
commit38b275f345755c035b4f13d23a5116c23494a311 (patch)
tree7ccf91707919c16f75b3dbb5961d6586dc50a543
parent7cf4fe846a1f32831d6c857a1eeb44494033da73 (diff)
downloadeclipse.platform.swt-38b275f345755c035b4f13d23a5116c23494a311.tar.gz
eclipse.platform.swt-38b275f345755c035b4f13d23a5116c23494a311.tar.xz
eclipse.platform.swt-38b275f345755c035b4f13d23a5116c23494a311.zip
Bug 550017 - Disabling StyledText changes cursor position and selection
Change-Id: I55c35ee8dd1b3e7044690414f0d8301127594e4a Signed-off-by: Andrey Loskutov <loskutov@gmx.de> Also-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java1
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java26
2 files changed, 26 insertions, 1 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 0762e3f3ae..5e6c186089 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
@@ -8965,7 +8965,6 @@ public void setEnabled (boolean enabled) {
if (!customBackground) setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
if (!customForeground) setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
} else {
- setSelectionRange(0,0);
if (!customBackground) setBackground(display.getSystemColor(SWT.COLOR_TEXT_DISABLED_BACKGROUND));
if (!customForeground) setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DISABLED_FOREGROUND));
}
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 c11d4b4ff0..897dbf680f 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
@@ -5584,4 +5584,30 @@ public void test_GlyphMetricsOnTab() {
assertEquals("Style should change text bounds", boundsWithoutGlyphMetrics.width - tabWidthWithoutGlyphMetrics + tabWidthWithGlyphMetrics, boundsWithGlyphMetrics.width);
}
+/**
+ * Test for:
+ * Bug 550017 - [StyledText] Disabling StyledText moves insertion position to 0
+ */
+@Test
+public void test_InsertWhenDisabled() {
+ String str = "some test text";
+ text.setText(str);
+ String selected = "test";
+ int selectionStart = str.indexOf(selected);
+ int selectionEnd = selectionStart + selected.length();
+ text.setSelection(selectionStart, selectionEnd);
+ assertEquals(selectionEnd, text.getCaretOffset());
+ assertEquals(selected, text.getSelectionText());
+
+ text.setEnabled(false);
+
+ assertEquals(selected, text.getSelectionText());
+ assertEquals(selectionEnd, text.getCaretOffset());
+
+ text.insert("[inserted]");
+ String actualText = text.getText();
+ String expectedText = "some [inserted] text";
+ assertEquals("Wrong insert in disabled StyledText", expectedText, actualText);
+}
+
}

Back to the top