Skip to content

Commit fa048d2

Browse files
authored
Merge pull request #1175 from wordpress-mobile/issue/refactor-public-independent-key-commands
Refactor TextView key commands.
2 parents d130f05 + 26164fb commit fa048d2

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

Aztec/Classes/TextKit/TextView.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,27 @@ open class TextView: UITextView {
486486

487487
// MARK: - Intercept Keystrokes
488488

489+
public lazy var carriageReturnKeyCommand: UIKeyCommand = {
490+
return UIKeyCommand(input: String(.carriageReturn), modifierFlags: .shift, action: #selector(handleShiftEnter(command:)))
491+
}()
492+
493+
public lazy var tabKeyCommand: UIKeyCommand = {
494+
return UIKeyCommand(input: String(.tab), modifierFlags: [], action: #selector(handleTab(command:)))
495+
}()
496+
497+
public lazy var shiftTabKeyCommand: UIKeyCommand = {
498+
return UIKeyCommand(input: String(.tab), modifierFlags: .shift, action: #selector(handleShiftTab(command:)))
499+
}()
500+
489501
override open var keyCommands: [UIKeyCommand]? {
490502
get {
491503
// When the keyboard "enter" key is pressed, the keycode corresponds to .carriageReturn,
492504
// even if it's later converted to .lineFeed by default.
493505
//
494506
return [
495-
UIKeyCommand(input: String(.carriageReturn), modifierFlags: .shift, action: #selector(handleShiftEnter(command:))),
496-
UIKeyCommand(input: String(.tab), modifierFlags: .shift, action: #selector(handleShiftTab(command:))),
497-
UIKeyCommand(input: String(.tab), modifierFlags: [], action: #selector(handleTab(command:)))
507+
carriageReturnKeyCommand,
508+
shiftTabKeyCommand,
509+
tabKeyCommand,
498510
]
499511
}
500512
}

0 commit comments

Comments
 (0)