From 708e090aef81c59904c483a2ea46b275ef21c7e4 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 19 Apr 2011 12:01:17 +1000 Subject: Fix excessive scrolling in TextInput with mid string pre-edit text. Don't emit text or cursor position changed signals until all the state changes from the input method event are made. Otherwise properties like horizontal scroll are updated based on invalid intermediate data. Change-Id: If543dbe58dc571aeda495152d99be95645eea140 Task-number: QTBUG-18789 Reviewed-by: Martin Jones --- src/gui/widgets/qlinecontrol.cpp | 2 +- .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp index 5a281ad..d03e5de 100644 --- a/src/gui/widgets/qlinecontrol.cpp +++ b/src/gui/widgets/qlinecontrol.cpp @@ -435,7 +435,7 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event) removeSelectedText(); } if (!event->commitString().isEmpty()) { - insert(event->commitString()); + internalInsert(event->commitString()); cursorPositionChanged = true; } diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index ef32ee3..943b1fa 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -2285,6 +2285,20 @@ void tst_qdeclarativetextinput::preeditAutoScroll() ic.sendPreeditText(preeditText.mid(0, 3), 1); QCOMPARE(input.positionAt(0), 0); QCOMPARE(input.positionAt(input.width()), 5); + + ic.sendEvent(QInputMethodEvent()); + input.setAutoScroll(true); + // Test committing pre-edit text at the start of the string. QTBUG-18789 + input.setCursorPosition(0); + ic.sendPreeditText(input.text(), 5); + QCOMPARE(input.positionAt(0), 0); + + QInputMethodEvent event; + event.setCommitString(input.text()); + ic.sendEvent(event); + + QCOMPARE(input.positionAt(0), 0); + QCOMPARE(input.positionAt(input.width()), 5); } void tst_qdeclarativetextinput::preeditMicroFocus() -- cgit v0.12