ctlIME // Refactor handle(event:client:) with guard let.

This commit is contained in:
ShikiSuen 2022-05-16 23:15:39 +08:00
parent 82707e89b6
commit 7bc0b5cc25
1 changed files with 14 additions and 3 deletions

View File

@ -148,7 +148,7 @@ class ctlInputMethod: IMKInputController {
return Int(events.rawValue)
}
override func handle(_ event: NSEvent!, client: Any!) -> Bool {
@objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
// flags使 KeyHandler
// flags
// event.type == .flagsChanged return false
@ -161,13 +161,18 @@ class ctlInputMethod: IMKInputController {
ctlInputMethod.areWeDeleting = event.modifierFlags.contains([.shift, .command])
var textFrame = NSRect.zero
let attributes: [AnyHashable: Any]? = (client as? IMKTextInput)?.attributes(
guard let client = sender as? IMKTextInput else {
return false
}
let attributes: [AnyHashable: Any]? = client.attributes(
forCharacterIndex: 0, lineHeightRectangle: &textFrame
)
let useVerticalMode =
(attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false
if (client as? IMKTextInput)?.bundleIdentifier()
if client.bundleIdentifier()
== "org.atelierInmu.vChewing.vChewingPhraseEditor"
{
IME.areWeUsingOurOwnPhraseEditor = true
@ -177,6 +182,12 @@ class ctlInputMethod: IMKInputController {
let input = InputHandler(event: event, isVerticalMode: useVerticalMode)
//
// KeyHandler
if !input.charCode.isPrintable() {
return false
}
let result = keyHandler.handle(input: input, state: state) { newState in
self.handle(state: newState, client: client)
} errorCallback: {