ctlInputMethod // Make the IME works with Terminal.app from now on.

This commit is contained in:
ShikiSuen 2022-02-14 20:45:18 +08:00
parent 47fb526078
commit 0bfb465ee3
1 changed files with 0 additions and 14 deletions

View File

@ -186,11 +186,6 @@ class ctlInputMethod: IMKInputController {
let attributes: [AnyHashable: Any]? = (client as? IMKTextInput)?.attributes(forCharacterIndex: 0, lineHeightRectangle: &textFrame) let attributes: [AnyHashable: Any]? = (client as? IMKTextInput)?.attributes(forCharacterIndex: 0, lineHeightRectangle: &textFrame)
let useVerticalMode = (attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false let useVerticalMode = (attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false
if (client as? IMKTextInput)?.bundleIdentifier() == "com.apple.Terminal" &&
NSStringFromClass(client.self as! AnyClass) == "IPMDServerClientWrapper" {
currentDeferredClient = client
}
let input = KeyHandlerInput(event: event, isVerticalMode: useVerticalMode) let input = KeyHandlerInput(event: event, isVerticalMode: useVerticalMode)
let result = keyHandler.handle(input: input, state: state) { newState in let result = keyHandler.handle(input: input, state: state) { newState in
@ -332,15 +327,6 @@ extension ctlInputMethod {
if buffer.isEmpty { if buffer.isEmpty {
return return
} }
// if it's Terminal, we don't commit at the first call (the client of which will not be IPMDServerClientWrapper)
// then we defer the update in the next runloop round -- so that the composing buffer is not
// meaninglessly flushed, an annoying bug in Terminal.app since Mac OS X 10.5
if (client as? IMKTextInput)?.bundleIdentifier() == "com.apple.Terminal" && NSStringFromClass(client.self as! AnyClass) != "IPMDServerClientWrapper" {
let innerCurrentDeferredClient = currentDeferredClient
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()) {
(innerCurrentDeferredClient as? IMKTextInput)?.insertText(buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound))
}
}
(client as? IMKTextInput)?.insertText(buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound)) (client as? IMKTextInput)?.insertText(buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound))
} }