aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2016-03-04 11:34:59 +0100
committerAndy Shaw <andy.shaw@qt.io>2017-07-26 18:10:36 +0000
commitbb199cc8ad4111808260f6255312b08c7d81dcbc (patch)
treeb8be1091223205ba8f1299563c72ae4436e5a1c2 /tests
parented90226834f8d4ef76149e995e2aecff68e4df43 (diff)
QQuickTextInput: Don't move the cursor after internalInsert() has done so
internalInsert() will set the cursor to the right position which accounts for any input mask set on the control as well. Therefore it will already be placed at the next correct position and should not be changed again after that. Task-number: QTBUG-40943 Change-Id: Ic80193ee94d2aa002b5a14a88df719a5a2cf51b1 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
index 67921e1fd0..2e20275193 100644
--- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
+++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp
@@ -215,6 +215,7 @@ private slots:
void clearInputMask();
void keypress_inputMask_data();
void keypress_inputMask();
+ void keypress_inputMethod_inputMask();
void hasAcceptableInputMask_data();
void hasAcceptableInputMask();
void maskCharacter_data();
@@ -2291,8 +2292,9 @@ void tst_qquicktextinput::inputMethods()
QGuiApplication::sendEvent(input, &event);
QCOMPARE(input->text(), QString("Our Goodbye world!"));
QCOMPARE(input->displayText(), QString("Our Goodbye world!"));
- QCOMPARE(input->cursorPosition(), 7);
+ QCOMPARE(input->cursorPosition(), 3);
+ input->setCursorPosition(7);
QInputMethodEvent preeditEvent("PREEDIT", QList<QInputMethodEvent::Attribute>());
QGuiApplication::sendEvent(input, &preeditEvent);
QCOMPARE(input->text(), QString("Our Goodbye world!"));
@@ -6481,6 +6483,48 @@ void tst_qquicktextinput::keypress_inputMask()
QCOMPARE(textInput->displayText(), expectedDisplayText);
}
+void tst_qquicktextinput::keypress_inputMethod_inputMask()
+{
+ // Similar to the keypress_inputMask test, but this is done solely via
+ // input methods
+ QString componentStr = "import QtQuick 2.0\nTextInput { focus: true; inputMask: \"AA.AA.AA\" }";
+ QQmlComponent textInputComponent(&engine);
+ textInputComponent.setData(componentStr.toLatin1(), QUrl());
+ QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create());
+ QVERIFY(textInput != 0);
+
+ QQuickWindow window;
+ textInput->setParentItem(window.contentItem());
+ window.show();
+ window.requestActivate();
+ QTest::qWaitForWindowActive(&window);
+ QVERIFY(textInput->hasActiveFocus());
+
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("EE");
+ QGuiApplication::sendEvent(textInput, &event);
+ }
+ QCOMPARE(textInput->cursorPosition(), 3);
+ QCOMPARE(textInput->text(), QStringLiteral("EE.."));
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("EE");
+ QGuiApplication::sendEvent(textInput, &event);
+ }
+ QCOMPARE(textInput->cursorPosition(), 6);
+ QCOMPARE(textInput->text(), QStringLiteral("EE.EE."));
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("EE");
+ QGuiApplication::sendEvent(textInput, &event);
+ }
+ QCOMPARE(textInput->cursorPosition(), 8);
+ QCOMPARE(textInput->text(), QStringLiteral("EE.EE.EE"));
+}
void tst_qquicktextinput::hasAcceptableInputMask_data()
{