From f0fcbe5265a939a0629eb996cbafecf8b5ae5ff9 Mon Sep 17 00:00:00 2001 From: Tobias Melcher Date: Sun, 24 Nov 2024 18:15:01 +0100 Subject: [PATCH] don't modify topIndex in handleTextChanged if control has not the focus --- .../common/org/eclipse/swt/custom/StyledText.java | 2 +- .../tests/junit/Test_org_eclipse_swt_custom_StyledText.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 c0c6c7e1e72..a37328c41ff 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 @@ -6046,7 +6046,7 @@ void handleTextChanged(TextChangedEvent event) { } int firstLine = content.getLineAtOffset(lastTextChangeStart); resetCache(firstLine, 0); - if (!isFixedLineHeight() && topIndex > firstLine) { + if (!isFixedLineHeight() && isFocusControl() && topIndex > firstLine) { topIndex = firstLine; if (topIndex < 0) { // TODO: This logging is in place to determine why topIndex is getting set to negative values. 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 e460ab4a619..dbc8fb0cecc 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 @@ -4790,6 +4790,10 @@ public void test_notFixedLineHeightDoesntChangeLinePixelIfUnnecessary() { int firstLinePixel = text.getLinePixel(line); text.setWordWrap(true); // make non fixed line height assertEquals(firstLinePixel, text.getLinePixel(line)); + shell.setVisible(true); + text.setVisible(true); + text.setFocus(); + assertTrue(text.isFocusControl()); text.replaceTextRange(0, 1, "X"); assertEquals(0, text.getTopIndex()); assertEquals(0, text.getLinePixel(0));