From afa1c138c5a9f745358ea4c9885ce6292e61299a Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 2 Feb 2021 16:24:58 +0100 Subject: qquicktextinput: ensure we update IM when cursor changes position Normally the cursor will change position inside a text input after receiving a touch or a keypress event. But it can also change position by sending it a QInputMethodEvent. But as it stood, we would in that case not inform the platform input context about it, which meant that the IM state in QQuickTextInput would be different from the IM state in QPA. A bug on iOS could be seen from this when dragging the cursor around using the magnifier glass. In that case QIOSTextResponder would move the cursor in QQuickTextInput using QInputMethodEvents. But since this would not be forwarded back to UITextInput, the result would be that if you e.g pushed backspace on the input panel, you would delete the character at the position the cursor had before the drag. This patch will ensure that we update platform IM state whenever the cursor changes position from QInputMethodEvents. Fixes: QTBUG-72757 Change-Id: Ic39c60fbce982f80d014befddbb2d4439ddeea4f Reviewed-by: Mitch Curtis Reviewed-by: Paul Olav Tvete (cherry picked from commit 04c0615352e947a23bcd52a0da4f901b3decdb87) Reviewed-by: Qt Cherry-pick Bot --- src/quick/items/qquicktextinput.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 8a9827a0be..daa92d8d20 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -3494,11 +3494,10 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event) m_textLayout.setFormats(formats); updateDisplayText(/*force*/ true); - if ((cursorPositionChanged && !emitCursorPositionChanged()) - || m_preeditCursor != oldPreeditCursor - || isGettingInput) { + if (cursorPositionChanged && emitCursorPositionChanged()) + q->updateInputMethod(Qt::ImCursorPosition | Qt::ImAnchorPosition); + else if (m_preeditCursor != oldPreeditCursor || isGettingInput) q->updateCursorRectangle(); - } if (isGettingInput) finishChange(priorState); -- cgit v1.2.3