From: Pekka Vuorela Date: Tue, 13 Dec 2011 13:47:51 +0000 (+0200) Subject: QQuickLineControl more robust on input method & selection state X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=0332e605f916ff67ce579172e857e457e8ea3e41;p=konrad%2Fqtdeclarative.git QQuickLineControl more robust on input method & selection state 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 Reviewed-by: Joona Petrell --- diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 903769b..a114caf 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -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()) { diff --git a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp index 51ee89a..5576345 100644 --- a/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/qtquick2/qquicktextinput/tst_qquicktextinput.cpp @@ -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()); } /*