diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-06-16 16:42:31 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-15 00:21:22 +0000 |
commit | 084331dd7322f8e61f59f5293fcba76266ab30f6 (patch) | |
tree | 6abfa307c4df35e977f746b4c0da3ee4c1abbbf9 /src/quick/items | |
parent | 4757cac470edbeaeaceca4e63075d9f1139f546b (diff) |
QQuickTextInput: fix cursor positioning for QInputMethodEvent
On Android the cursor position was calculated incorrectly, which
could results in rewriting the previously entered symbol.
Change-Id: I7404979e098974d2e2cd8c91c6012cf5a52909b2
Fixes: QTBUG-94253
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit f2eeba67846dbf6fe66066a2296e50b02533e672)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 8840d8f49b..4c76352171 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -3458,7 +3458,12 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event) for (int i = 0; i < event->attributes().size(); ++i) { const QInputMethodEvent::Attribute &a = event->attributes().at(i); if (a.type == QInputMethodEvent::Selection) { - m_cursor = qBound(0, a.start + a.length, m_text.length()); + // If we already called internalInsert(), the cursor position will + // already be adjusted correctly. The attribute.start does + // not seem to take the mask into account, so it will reset cursor + // to an invalid position in such case. + if (!cursorPositionChanged) + m_cursor = qBound(0, a.start + a.length, m_text.length()); if (a.length) { m_selstart = qMax(0, qMin(a.start, m_text.length())); m_selend = m_cursor; |