From fc9baeeb9f6360051cb02d1da6c094aa8154f58e Mon Sep 17 00:00:00 2001 From: Vova Mshanetskiy Date: Thu, 25 Apr 2019 17:02:44 +0300 Subject: QWidgetTextControl: Emit cursorPositionChanged() when handling IM event QWidgetTextControl and consequently QTextEdit did not emit cursorPositionChanged() signal when cursor position was changed by a QInputMethodEvent with a QInputMethodEvent::Selection attribute. This is especially important on Android because QAndroidInputContext uses such events extensively to move the cursor and also relies on cursorPositionChanged() signal being emitted by the focus object. If the signal is not emitted, QAndroidInputContext does not notify the virtual keyboard about cursor position change which results in various glitches. Change-Id: I7edd141258c483e6f103adcd6e40049b49c13387 Reviewed-by: Richard Moe Gustavsen --- src/widgets/widgets/qwidgettextcontrol.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index e179ea3b40..6b8ce63380 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -1974,6 +1974,8 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) || e->preeditString() != cursor.block().layout()->preeditAreaText() || e->replacementLength() > 0; + int oldCursorPos = cursor.position(); + cursor.beginEditBlock(); if (isGettingInput) { cursor.removeSelectedText(); @@ -2078,6 +2080,8 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) if (cursor.d) cursor.d->setX(); + if (oldCursorPos != cursor.position()) + emit q->cursorPositionChanged(); if (oldPreeditCursor != preeditCursor) emit q->microFocusChanged(); } -- cgit v1.2.3