Skip to content

Commit f0fcbe5

Browse files
don't modify topIndex in handleTextChanged if control has not the focus
1 parent 37b22fb commit f0fcbe5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6046,7 +6046,7 @@ void handleTextChanged(TextChangedEvent event) {
60466046
}
60476047
int firstLine = content.getLineAtOffset(lastTextChangeStart);
60486048
resetCache(firstLine, 0);
6049-
if (!isFixedLineHeight() && topIndex > firstLine) {
6049+
if (!isFixedLineHeight() && isFocusControl() && topIndex > firstLine) {
60506050
topIndex = firstLine;
60516051
if (topIndex < 0) {
60526052
// TODO: This logging is in place to determine why topIndex is getting set to negative values.

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,6 +4790,10 @@ public void test_notFixedLineHeightDoesntChangeLinePixelIfUnnecessary() {
47904790
int firstLinePixel = text.getLinePixel(line);
47914791
text.setWordWrap(true); // make non fixed line height
47924792
assertEquals(firstLinePixel, text.getLinePixel(line));
4793+
shell.setVisible(true);
4794+
text.setVisible(true);
4795+
text.setFocus();
4796+
assertTrue(text.isFocusControl());
47934797
text.replaceTextRange(0, 1, "X");
47944798
assertEquals(0, text.getTopIndex());
47954799
assertEquals(0, text.getLinePixel(0));

0 commit comments

Comments
 (0)