summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-11-25 12:30:41 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-09 09:36:05 +0000
commit7bee5fa2ce5ef7ed3f1da1a336c21a74ceeaec7c (patch)
treeeb48c6338438faa21b23f6424288ed2aa567f80a /src/plugins/platforms/ios
parente98922bbde9e66e5355afa61857c1ecb70ee8df1 (diff)
iOS: filter edit menu actions depending on selection state
When showing an edit menu on iOS, UIKit will always populate the menu with actions according to what the current first responder supports. But it doesn't make sense to show all the actions every time the menu opens, so introduce some filtering depending on selection state. Change-Id: I943a09928233a3a10de003fe15ed8fd8b6fc1e18 Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiostextresponder.mm26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm
index 434ba2edc6..770dadd3e4 100644
--- a/src/plugins/platforms/ios/qiostextresponder.mm
+++ b/src/plugins/platforms/ios/qiostextresponder.mm
@@ -364,6 +364,32 @@
[self sendKeyPressRelease:key modifiers:modifiers];
}
+- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
+{
+ bool isEditAction = (action == @selector(cut:)
+ || action == @selector(copy:)
+ || action == @selector(paste:)
+ || action == @selector(delete:)
+ || action == @selector(toggleBoldface:)
+ || action == @selector(toggleItalics:)
+ || action == @selector(toggleUnderline:)
+ || action == @selector(undo)
+ || action == @selector(redo));
+
+ bool isSelectAction = (action == @selector(select:)
+ || action == @selector(selectAll:)
+ || action == @selector(paste:)
+ || action == @selector(undo)
+ || action == @selector(redo));
+
+ const bool unknownAction = !isEditAction && !isSelectAction;
+ const bool hasSelection = ![self selectedTextRange].empty;
+
+ if (unknownAction)
+ return [super canPerformAction:action withSender:sender];
+ return (hasSelection && isEditAction) || (!hasSelection && isSelectAction);
+}
+
- (void)cut:(id)sender
{
Q_UNUSED(sender);