diff options
author | Andreas Buhr <andreas.buhr@qt.io> | 2021-10-14 05:20:23 +0200 |
---|---|---|
committer | Andreas Buhr <andreas.buhr@qt.io> | 2021-10-14 17:20:58 +0200 |
commit | a47f66cee280cef1e5854f3ed187e9f2be19697a (patch) | |
tree | c35aef8eb2550a4ae437d1fdb04ace5297a039c9 /src/plugins/platforms/android/qandroidinputcontext.cpp | |
parent | 2e73ff10797b9b069cf7abd8c353ad60bd6a088a (diff) |
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 <paul.tvete@qt.io>
Diffstat (limited to 'src/plugins/platforms/android/qandroidinputcontext.cpp')
-rw-r--r-- | src/plugins/platforms/android/qandroidinputcontext.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
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<QInputMethodEvent::Attribute> attributes; - attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0)); - - QInputMethodEvent event(QString(), attributes); - event.setCommitString(m_composingText); - sendInputMethodEvent(&event); + { + // commit the composing test + QList<QInputMethodEvent::Attribute> attributes; + QInputMethodEvent event(QString(), attributes); + event.setCommitString(m_composingText); + sendInputMethodEvent(&event); + } + { + // Moving Qt's cursor to where the preedit cursor used to be + QList<QInputMethodEvent::Attribute> attributes; + attributes.append( + QInputMethodEvent::Attribute(QInputMethodEvent::Selection, localCursorPos, 0)); + QInputMethodEvent event(QString(), attributes); + sendInputMethodEvent(&event); + } return true; } |