diff options
6 files changed, 39 insertions, 11 deletions
diff --git a/src/quick/items/qquicktextcontrol.cpp b/src/quick/items/qquicktextcontrol.cpp index 8bc94b919c..751706dce1 100644 --- a/src/quick/items/qquicktextcontrol.cpp +++ b/src/quick/items/qquicktextcontrol.cpp @@ -1479,7 +1479,7 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) QTextCursorPrivate *cursor_d = QTextCursorPrivate::getPrivate(&cursor); if (cursor_d) cursor_d->setX(); - q->updateCursorRectangle(oldPreeditCursor != preeditCursor || forceSelectionChanged); + q->updateCursorRectangle(oldPreeditCursor != preeditCursor || forceSelectionChanged || isGettingInput); selectionChanged(forceSelectionChanged); } diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 9cf187e7a0..e2199347e7 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -3217,7 +3217,7 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event) updateDisplayText(/*force*/ true); if (cursorPositionChanged) { emitCursorPositionChanged(); - } else if (m_preeditCursor != oldPreeditCursor) { + } else if (m_preeditCursor != oldPreeditCursor || isGettingInput) { q->updateCursorRectangle(); } @@ -3332,7 +3332,7 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo emit q->selectionChanged(); } - inputMethodAttributesChanged |= (m_cursor == m_lastCursorPos); + inputMethodAttributesChanged |= (m_cursor != m_lastCursorPos); if (inputMethodAttributesChanged) q->updateInputMethod(); emitUndoRedoChanged(); diff --git a/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml b/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml index ab47368619..7df7a558f9 100644 --- a/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml +++ b/tests/auto/quick/qquicktextedit/data/inputMethodEvent.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 TextEdit { + width: 300 focus: true cursorDelegate: Item { diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 51b04cf7a0..1b21fcc2b4 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -2858,11 +2858,11 @@ void tst_qquicktextedit::preeditCursorRectangle() QCOMPARE(edit->cursorRectangle(), currentRect); QCOMPARE(cursor->pos(), currentRect.topLeft()); QCOMPARE(currentRect, previousRect); - QCOMPARE(editSpy.count(), 0); editSpy.clear(); - QCOMPARE(panelSpy.count(), 0); panelSpy.clear(); // Verify that the micro focus rect moves to the left as the cursor position // is incremented. + editSpy.clear(); + panelSpy.clear(); for (int i = 1; i <= 5; ++i) { QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>() << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, preeditText.length(), QVariant())); @@ -2877,9 +2877,22 @@ void tst_qquicktextedit::preeditCursorRectangle() previousRect = currentRect; } + // Verify that if the cursor rectangle is updated if the pre-edit text changes + // but the (non-zero) cursor position is the same. + editSpy.clear(); + panelSpy.clear(); + { QInputMethodEvent imEvent("wwwww", QList<QInputMethodEvent::Attribute>() + << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 5, 1, QVariant())); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); } + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); + QCOMPARE(edit->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); + QCOMPARE(editSpy.count(), 1); + QCOMPARE(panelSpy.count(), 1); + // Verify that if there is no preedit cursor then the micro focus rect is the // same as it would be if it were positioned at the end of the preedit text. - QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); editSpy.clear(); panelSpy.clear(); { QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>()); diff --git a/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml b/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml index 907ea68b10..9e04620d8f 100644 --- a/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml +++ b/tests/auto/quick/qquicktextinput/data/inputMethodEvent.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 TextInput { + width: 300 focus: true autoScroll: false diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 2ea24867af..e80808badf 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -3437,18 +3437,31 @@ void tst_qquicktextinput::preeditCursorRectangle() previousRect = currentRect; } + // Verify that if the cursor rectangle is updated if the pre-edit text changes + // but the (non-zero) cursor position is the same. + inputSpy.clear(); + panelSpy.clear(); + sendPreeditText("wwwww", 5); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); + currentRect = query.value(Qt::ImCursorRectangle).toRectF(); + QCOMPARE(input->cursorRectangle(), currentRect); + QCOMPARE(cursor->pos(), currentRect.topLeft()); + QCOMPARE(inputSpy.count(), 1); + QCOMPARE(panelSpy.count(), 1); + // Verify that if there is no preedit cursor then the micro focus rect is the // same as it would be if it were positioned at the end of the preedit text. - sendPreeditText(preeditText, 0); - QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>()); - QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); + inputSpy.clear(); + panelSpy.clear(); + { QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>()); + QCoreApplication::sendEvent(qGuiApp->focusObject(), &imEvent); } QCoreApplication::sendEvent(qGuiApp->focusObject(), &query); currentRect = query.value(Qt::ImCursorRectangle).toRectF(); QCOMPARE(currentRect, previousRect); QCOMPARE(input->cursorRectangle(), currentRect); QCOMPARE(cursor->pos(), currentRect.topLeft()); - QVERIFY(inputSpy.count() > 0); - QVERIFY(panelSpy.count() > 0); + QCOMPARE(inputSpy.count(), 1); + QCOMPARE(panelSpy.count(), 1); } void tst_qquicktextinput::inputContextMouseHandler() |