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 c0c6c7e1e7..a37328c41f 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 e460ab4a61..dbc8fb0cec 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));