QQuickLineControl more robust on input method & selection state
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Tue, 13 Dec 2011 13:47:51 +0000 (15:47 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 20 Dec 2011 11:40:31 +0000 (12:40 +0100)
Input method event having replacement information out of bounds
left the controller in selection state when it shouldn't be.
Also now more liberal on accepted events. We cannot detect if input
method is confused for replacement inside boundaries, but going beyond
the end is more likely to be meant to replace until the end than to
leave previous text in addition to the new one.

Change-Id: I485009ac682c11876b39f7e22d7dfb91a6d162fe
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
src/quick/items/qquicktextinput.cpp
tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp

index 903769b..a114caf 100644 (file)
@@ -2570,6 +2570,7 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event)
     if (event->replacementLength()) {
         m_selstart = m_cursor;
         m_selend = m_selstart + event->replacementLength();
+        m_selend = qMin(m_selend, m_text.length());
         removeSelectedText();
     }
     if (!event->commitString().isEmpty()) {
index 51ee89a..5576345 100644 (file)
@@ -1659,6 +1659,14 @@ void tst_qquicktextinput::inputMethods()
     QCOMPARE(input->text(), QString(""));
     input->setValidator(0);
     delete validator;
+
+    // input should reset selection even if replacement parameters are out of bounds
+    input->setText("text");
+    input->setCursorPosition(0);
+    input->moveCursorSelection(input->text().length());
+    event.setCommitString("replacement", -input->text().length(), input->text().length());
+    QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event);
+    QCOMPARE(input->selectionStart(), input->selectionEnd());
 }
 
 /*