Skip to content

Commit 49fd6b0

Browse files
don't modify topIndex in handleTextChanged if control has not the focus (eclipse-platform#1617)
Co-authored-by: Tobias Melcher <[email protected]>
1 parent 238bc0c commit 49fd6b0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,6 +4792,11 @@ public void test_notFixedLineHeightDoesntChangeLinePixelIfUnnecessary() {
47924792
int firstLinePixel = text.getLinePixel(line);
47934793
text.setWordWrap(true); // make non fixed line height
47944794
assertEquals(firstLinePixel, text.getLinePixel(line));
4795+
shell.setVisible(true);
4796+
shell.forceActive();
4797+
text.setVisible(true);
4798+
assertTrue("setFocus failed",text.setFocus());
4799+
assertTrue("text has not focus",text.isFocusControl());
47954800
text.replaceTextRange(0, 1, "X");
47964801
assertEquals(0, text.getTopIndex());
47974802
assertEquals(0, text.getLinePixel(0));

0 commit comments

Comments
 (0)