diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-06-16 16:42:31 +0200 |
---|---|---|
committer | Andreas Buhr <andreas@andreasbuhr.de> | 2021-10-14 16:50:24 +0200 |
commit | f2eeba67846dbf6fe66066a2296e50b02533e672 (patch) | |
tree | 05cee1a035897c37fe62918f5efb1377f003eec5 /src/quick/items/qquicktextinput.cpp | |
parent | e78d36789ff4a7773c51147589837b1bc6a8d5e2 (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
Pick-to: 6.2 5.15
Reviewed-by: Andreas Buhr <andreas.buhr@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/quick/items/qquicktextinput.cpp')
-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 6b0babd182..dd16ff430e 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -3461,7 +3461,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; |