From f2eeba67846dbf6fe66066a2296e50b02533e672 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Wed, 16 Jun 2021 16:42:31 +0200 Subject: 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 Reviewed-by: Richard Moe Gustavsen --- src/quick/items/qquicktextinput.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/quick/items') 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; -- cgit v1.2.3