PressBegan() invoked twice when pressing Command + key on UITextView/UITextField

I am observing an unexpected behavior with external keyboard input on iOS.

When I press Command + key (e.g., ⌘ + J) while a UITextView is focused, the system invokes

pressesBegan(_ presses: Set<UIPress>, with event: UIPressesEvent?) twice:

-> Once with the key press event without any modifier flags.

-> A second time with the same key event but including the Command modifier flag.

This behavior is checked on an iPad with an external keyboard.

Additionally, I noticed that textView(_:shouldChangeTextIn:replacementText:) is not invoked in this case, even if I call super.pressesBegan for event propagation.

Questions:

Is it expected that pressesBegan fires twice for a Command + key combination?

If so, what is the recommended way to distinguish between these two invocations?

Should the UITextView delegate methods (like shouldChangeTextIn) be triggered for such key combinations, or is this by design?

It is expected in some cases to get two different presses and two pressesBegan|Changed|Ended|Cancelled callbacks.

They shouldn't be exactly the same though. Only one of the presses should have the key property set, which contains the UIKey info for that press. That is the one you most likely want to listen for when doing manual event handling for presses.

The other one should have the key property be nil and instead have a type set, which is only relevant if you want to react to one of the semantic UIPressType values such as UIPressTypeMenu etc.

PressBegan() invoked twice when pressing Command &#43; key on UITextView/UITextField
 
 
Q