From 3409cda1bccff865598b29001db8598434707816 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 3 Feb 2021 10:02:51 +0100 Subject: iOS: hide edit menu if typing on the input panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On iOS, if you select some text, the edit menu will show on top of it. And if you tap on the screen (or inside the menu) it will hide. But if you type on the input panel, it will stay open. This is wrong. This patch will keep better track of whether or not the edit menu was opened by us, and if it was, ensure we close it also if the cursor moves by typing on the input panel. Fixes: QTBUG-90860 Change-Id: I0a51382030560182e7925c8b694b42e50943514e Reviewed-by: Morten Johan Sørvig (cherry picked from commit b39081230428a9cc08389342c4610d11b2ee210d) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/ios/qiostextinputoverlay.mm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/platforms/ios/qiostextinputoverlay.mm b/src/plugins/platforms/ios/qiostextinputoverlay.mm index 15be19c6bc..5cc9ebc5d5 100644 --- a/src/plugins/platforms/ios/qiostextinputoverlay.mm +++ b/src/plugins/platforms/ios/qiostextinputoverlay.mm @@ -92,6 +92,7 @@ static void executeBlockWithoutAnimation(Block block) @interface QIOSEditMenu : NSObject @property (nonatomic, assign) BOOL visible; @property (nonatomic, readonly) BOOL isHiding; +@property (nonatomic, readonly) BOOL shownByUs; @property (nonatomic, assign) BOOL reshowAfterHidden; @end @@ -110,6 +111,7 @@ static void executeBlockWithoutAnimation(Block block) [center addObserverForName:UIMenuControllerDidHideMenuNotification object:nil queue:nil usingBlock:^(NSNotification *) { _isHiding = NO; + _shownByUs = NO; if (self.reshowAfterHidden) { // To not abort an ongoing hide transition when showing the menu, you can set // reshowAfterHidden to wait until the transition finishes before reshowing it. @@ -144,6 +146,10 @@ static void executeBlockWithoutAnimation(Block block) return; if (visible) { + // UIMenuController is a singleton that can be shown (and hidden) from anywhere. + // Try to keep track of whether or not is was shown by us (the gesture recognizers + // in this file) to avoid closing it if it was opened from elsewhere. + _shownByUs = YES; // Note that the contents of the edit menu is decided by // first responder, which is normally QIOSTextResponder. QRectF cr = qApp->inputMethod()->cursorRectangle(); @@ -841,11 +847,9 @@ static void executeBlockWithoutAnimation(Block block) if (_cursorLayer.visible) { _cursorLayer.visible = NO; _anchorLayer.visible = NO; - // Only hide the edit menu if we had a selection from before, since - // the edit menu can also be used for other purposes by others (in - // which case we try our best not to interfere). - QIOSTextInputOverlay::s_editMenu.visible = NO; } + if (QIOSTextInputOverlay::s_editMenu.shownByUs) + QIOSTextInputOverlay::s_editMenu.visible = NO; return; } -- cgit v1.2.3