From be06164201d7d9ccdbaaff343af2e8f3662c044d Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 4 Feb 2021 13:33:56 +0100 Subject: [PATCH] iOS: don't report selection changed if it didn't change Be more careful about reporting a new selection to Qt. The code for handling IM selection events in QQuickTextArea is quite complex and need to take pre-edit text into account. The latter means that when the pre-edit text changes, as a result of the user composing a word, the width of the pre-edit text will also change (and as such, the cursor rectangle). But the cursor position itself stays the same. And for this reason, it emits cursorRectChanged more often than strictly needed. But rather than trying to clean that up, we do some extra checking before we send the IM event from QPA in the first place. Pick-to: 6.0 6.1 5.15 Fixes: QTBUG-63018 Change-Id: I689d989c3fe5d61ef2b1dbee7a70418b7790bce9 Reviewed-by: Andy Shaw --- src/plugins/platforms/ios/qiostextinputoverlay.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm index 5776c364c4..23359ec069 100644 --- a/src/plugins/platforms/ios/qiostextinputoverlay.mm +++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm @@ -640,8 +640,12 @@ static void executeBlockWithoutAnimation(Block block) - (void)updateFocalPoint:(QPointF)touchPoint { - QPlatformInputContext::setSelectionOnFocusObject(touchPoint, touchPoint); self.focalPoint = touchPoint; + + const int currentCursorPos = QInputMethod::queryFocusObject(Qt::ImCursorPosition, QVariant()).toInt(); + const int newCursorPos = QPlatformInputContext::queryFocusObject(Qt::ImCursorPosition, touchPoint).toInt(); + if (newCursorPos != currentCursorPos) + QPlatformInputContext::setSelectionOnFocusObject(touchPoint, touchPoint); } @end