From a47f66cee280cef1e5854f3ed187e9f2be19697a Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Thu, 14 Oct 2021 05:20:23 +0200 Subject: Android: Fix handling of cursor position when stop composing This is a workaround for a problem in TextEdit. The symptom is that when the user places the cursor inside of a word and hits backspace, the last letter of the word is removed instead of the letter just before the cursor. The reason is as follows. When stopping composing, the current cursor position has to be maintained. To that end, QAndroidInputContext sends an event containing the text to be committed and the cursor position to the editor. But the resulting cursor position is wrong. This patch adapts QAndroidInputContext to send two events: One to commit the text, the second to place the cursor. A real fix would fix the editor to correctly handle the event containing both the committed text and the cursor position. Fixes: QTBUG-97491 Pick-to: 6.2 5.15 Change-Id: Idd00e5afcbfe29c9cb77356f9add2e881c51b9bb Reviewed-by: Paul Olav Tvete --- .../platforms/android/qandroidinputcontext.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/plugins/platforms/android') diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index bfc1a1109f..37a5191dfc 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -1225,13 +1225,21 @@ bool QAndroidInputContext::focusObjectStopComposing() m_composingCursor = -1; - // Moving Qt's cursor to where the preedit cursor used to be - QList attributes; - attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0)); - - QInputMethodEvent event(QString(), attributes); - event.setCommitString(m_composingText); - sendInputMethodEvent(&event); + { + // commit the composing test + QList attributes; + QInputMethodEvent event(QString(), attributes); + event.setCommitString(m_composingText); + sendInputMethodEvent(&event); + } + { + // Moving Qt's cursor to where the preedit cursor used to be + QList attributes; + attributes.append( + QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0)); + QInputMethodEvent event(QString(), attributes); + sendInputMethodEvent(&event); + } return true; } -- cgit v1.2.3