How to enable the "Paste and Match Style" context menu in a UITextView?

The UIResponderStandardEditActions protocol includes pasteAndMatchStyle:. UITextView conforms to UIResponderStandardEditActions. But I can't find a way to get that menu to appear. I get the standard "Paste" menu. I've tried overriding pasteAndMatchStyle: in a subclass of UITextView. I've overridden canPerformAction:withSender: but it never gets called with the pasteAndMatchStyle: selector. I've implemented the textView:editMenuForTextInRange:suggestedActions: delegate method. It's called but the suggested actions do not include the "Paste and Match Style" action (key command).

I came up with an ugly hack that involved overriding buildMenuWithBuilder: and adding my own key command after the paste command. But this shouldn't be necessary considering it's supposed to be a standard edit action.

So what's the trick to make the "Paste and Match Style" edit menu appear properly in a UITextView? I'm testing with iOS 17, 18, and 26.

Answered by Frameworks Engineer in 860191022

By default context menus don't include a Paste and Match Style menu item, as it's not standard for that to be included in context menus (unlike the menu bar where it is standard to show that). If your app really wants to show this item, then overriding -buildMenuWithBuilder: and adding your own command with the standard pasteAndMatchStyle: action is the correct solution.

Accepted Answer

By default context menus don't include a Paste and Match Style menu item, as it's not standard for that to be included in context menus (unlike the menu bar where it is standard to show that). If your app really wants to show this item, then overriding -buildMenuWithBuilder: and adding your own command with the standard pasteAndMatchStyle: action is the correct solution.

Thanks. I got so focused on getting this added to the context menu I forgot about the “Paste and Match Style” item appearing in the Edit menu bar. Of course that only helps with the iPadOS 26 and Mac Catalyst versions of the app. For iPhones and for iPads on iPadOS before 26, my only option is to use the context menu. I guess I’ll stick with my buildMenuWithBuilder: approach.

How to enable the "Paste and Match Style" context menu in a UITextView?
 
 
Q