summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/widgets/qwidgetlinecontrol.cpp4
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp32
2 files changed, 34 insertions, 2 deletions
diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp
index 97df3427b0..976cd173c5 100644
--- a/src/widgets/widgets/qwidgetlinecontrol.cpp
+++ b/src/widgets/widgets/qwidgetlinecontrol.cpp
@@ -548,10 +548,10 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event)
if (!event->commitString().isEmpty()) {
internalInsert(event->commitString());
cursorPositionChanged = true;
+ } else {
+ m_cursor = qBound(0, c, m_text.length());
}
- m_cursor = qBound(0, c, m_text.length());
-
for (int i = 0; i < event->attributes().size(); ++i) {
const QInputMethodEvent::Attribute &a = event->attributes().at(i);
if (a.type == QInputMethodEvent::Selection) {
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 3f7fdd6f6f..b434e48500 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -147,6 +147,7 @@ private slots:
void keypress_inputMask_data();
void keypress_inputMask();
+ void keypress_inputMethod_inputMask();
void inputMaskAndValidator_data();
void inputMaskAndValidator();
@@ -803,6 +804,37 @@ void tst_QLineEdit::keypress_inputMask()
QCOMPARE(testWidget->displayText(), expectedDisplayText);
}
+void tst_QLineEdit::keypress_inputMethod_inputMask()
+{
+ // Similar to the keypress_inputMask test, but this is done solely via
+ // input methods
+ QLineEdit *testWidget = ensureTestWidget();
+ testWidget->setInputMask("AA.AA.AA");
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("EE");
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QCOMPARE(testWidget->cursorPosition(), 3);
+ QCOMPARE(testWidget->text(), QStringLiteral("EE.."));
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("EE");
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QCOMPARE(testWidget->cursorPosition(), 6);
+ QCOMPARE(testWidget->text(), QStringLiteral("EE.EE."));
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ QInputMethodEvent event("", attributes);
+ event.setCommitString("EE");
+ QApplication::sendEvent(testWidget, &event);
+ }
+ QCOMPARE(testWidget->cursorPosition(), 8);
+ QCOMPARE(testWidget->text(), QStringLiteral("EE.EE.EE"));
+}
void tst_QLineEdit::hasAcceptableInputMask_data()
{