QLineEdit: 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: Ic0f5fad6999ddd367e435ec4409a5db5b9eacb7b
Reviewed-by: Daniel Teske <qt@squorn.de>
Reviewed-by: David Faure <david.faure@kdab.com>
bb10
Andy Shaw 2017-07-13 14:37:00 +02:00
parent 3becc8527e
commit fcfee98f62
2 changed files with 34 additions and 2 deletions

View File

@ -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) {

View File

@ -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()
{