Is it possible to override UITextView's handling of cmd + z and cmd + shift + z ?
I've tried to
- override the
keyCommandproperty, but the selectors are never called.. - override the
undoManager, this doesn't help either
class CustomTextView: UITextView {
override var keyCommands: [UIKeyCommand]? {
[
// cmd + z (doesn't work)
UIKeyCommand(input: "z", modifierFlags: [.command], action: #selector(undo)),
// cmd + shift + z (doesn't work)
UIKeyCommand(input: "z", modifierFlags: [.command, .shift], action: #selector(redo)),
// z (works)
UIKeyCommand(input: "z", modifierFlags: [], action: #selector(z)),
]
}
// this doesn't help
override var undoManager: UndoManager? { return nil }
// undo
@objc private func undo() {
print("undo")
}
// redo
@objc private func redo() {
print("redo")
}
// z
@objc private func z() {
print("z")
}
}