ctlIME // Use IMK client() instead.

This commit is contained in:
ShikiSuen 2022-06-15 15:59:11 +08:00
parent 63c9bf87fd
commit c79b7c99a9
1 changed files with 17 additions and 21 deletions

View File

@ -39,10 +39,6 @@ class ctlInputMethod: IMKInputController {
// MARK: - // MARK: -
private var currentClient: IMKTextInput {
client()
}
private var keyHandler: KeyHandler = .init() private var keyHandler: KeyHandler = .init()
private var state: InputState = .Empty() private var state: InputState = .Empty()
@ -57,7 +53,7 @@ class ctlInputMethod: IMKInputController {
// MARK: - Keyboard Layout Specifier // MARK: - Keyboard Layout Specifier
@objc func setKeyLayout() { @objc func setKeyLayout() {
currentClient.overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout) client().overrideKeyboard(withKeyboardNamed: mgrPrefs.basicKeyboardLayout)
} }
// MARK: - IMKInputController methods // MARK: - IMKInputController methods
@ -86,7 +82,7 @@ class ctlInputMethod: IMKInputController {
keyHandler.clear() keyHandler.clear()
keyHandler.ensureParser() keyHandler.ensureParser()
if currentClient.bundleIdentifier() != Bundle.main.bundleIdentifier { if client().bundleIdentifier() != Bundle.main.bundleIdentifier {
// Override the keyboard layout to the basic one. // Override the keyboard layout to the basic one.
setKeyLayout() setKeyLayout()
handle(state: .Empty()) handle(state: .Empty())
@ -119,7 +115,7 @@ class ctlInputMethod: IMKInputController {
UserDefaults.standard.synchronize() UserDefaults.standard.synchronize()
keyHandler.clear() keyHandler.clear()
keyHandler.inputMode = newInputMode keyHandler.inputMode = newInputMode
if currentClient.bundleIdentifier() != Bundle.main.bundleIdentifier { if client().bundleIdentifier() != Bundle.main.bundleIdentifier {
// Remember to override the keyboard layout again -- treat this as an activate event. // Remember to override the keyboard layout again -- treat this as an activate event.
setKeyLayout() setKeyLayout()
handle(state: .Empty()) handle(state: .Empty())
@ -153,14 +149,14 @@ class ctlInputMethod: IMKInputController {
var textFrame = NSRect.zero var textFrame = NSRect.zero
let attributes: [AnyHashable: Any]? = currentClient.attributes( let attributes: [AnyHashable: Any]? = client().attributes(
forCharacterIndex: 0, lineHeightRectangle: &textFrame forCharacterIndex: 0, lineHeightRectangle: &textFrame
) )
let isTypingVertical = let isTypingVertical =
(attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false (attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false
if currentClient.bundleIdentifier() if client().bundleIdentifier()
== "org.atelierInmu.vChewing.vChewingPhraseEditor" == "org.atelierInmu.vChewing.vChewingPhraseEditor"
{ {
IME.areWeUsingOurOwnPhraseEditor = true IME.areWeUsingOurOwnPhraseEditor = true
@ -267,7 +263,7 @@ extension ctlInputMethod {
} }
} }
currentClient.insertText( client().insertText(
bufferOutput, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) bufferOutput, replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
} }
@ -282,7 +278,7 @@ extension ctlInputMethod {
if let previous = previous as? InputState.NotEmpty { if let previous = previous as? InputState.NotEmpty {
commit(text: previous.composingBuffer) commit(text: previous.composingBuffer)
} }
currentClient.setMarkedText( client().setMarkedText(
"", selectionRange: NSRange(location: 0, length: 0), "", selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -298,7 +294,7 @@ extension ctlInputMethod {
{ {
commit(text: previous.composingBuffer) commit(text: previous.composingBuffer)
} }
currentClient.setMarkedText( client().setMarkedText(
"", selectionRange: NSRange(location: 0, length: 0), "", selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -312,7 +308,7 @@ extension ctlInputMethod {
ctlCandidateCurrent.visible = false ctlCandidateCurrent.visible = false
hideTooltip() hideTooltip()
currentClient.setMarkedText( client().setMarkedText(
"", selectionRange: NSRange(location: 0, length: 0), "", selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -327,7 +323,7 @@ extension ctlInputMethod {
if !poppedText.isEmpty { if !poppedText.isEmpty {
commit(text: poppedText) commit(text: poppedText)
} }
currentClient.setMarkedText( client().setMarkedText(
"", selectionRange: NSRange(location: 0, length: 0), "", selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -345,7 +341,7 @@ extension ctlInputMethod {
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound, // the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put this composing buffer // i.e. the client app needs to take care of where to put this composing buffer
currentClient.setMarkedText( client().setMarkedText(
state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0), state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -363,7 +359,7 @@ extension ctlInputMethod {
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound, // the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put this composing buffer // i.e. the client app needs to take care of where to put this composing buffer
currentClient.setMarkedText( client().setMarkedText(
state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0), state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -384,7 +380,7 @@ extension ctlInputMethod {
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound, // the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put this composing buffer // i.e. the client app needs to take care of where to put this composing buffer
currentClient.setMarkedText( client().setMarkedText(
state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0), state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -397,7 +393,7 @@ extension ctlInputMethod {
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound, // the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put this composing buffer // i.e. the client app needs to take care of where to put this composing buffer
currentClient.setMarkedText( client().setMarkedText(
state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0), state.attributedString, selectionRange: NSRange(location: state.cursorIndex, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -408,7 +404,7 @@ extension ctlInputMethod {
_ = previous // Stop clang-format from ruining the parameters of this function. _ = previous // Stop clang-format from ruining the parameters of this function.
hideTooltip() hideTooltip()
currentClient.setMarkedText( client().setMarkedText(
"", selectionRange: NSRange(location: 0, length: 0), "", selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
@ -520,7 +516,7 @@ extension ctlInputMethod {
} }
while lineHeightRect.origin.x == 0, lineHeightRect.origin.y == 0, cursor >= 0 { while lineHeightRect.origin.x == 0, lineHeightRect.origin.y == 0, cursor >= 0 {
currentClient.attributes( client().attributes(
forCharacterIndex: cursor, lineHeightRectangle: &lineHeightRect forCharacterIndex: cursor, lineHeightRectangle: &lineHeightRect
) )
cursor -= 1 cursor -= 1
@ -548,7 +544,7 @@ extension ctlInputMethod {
cursor -= 1 cursor -= 1
} }
while lineHeightRect.origin.x == 0, lineHeightRect.origin.y == 0, cursor >= 0 { while lineHeightRect.origin.x == 0, lineHeightRect.origin.y == 0, cursor >= 0 {
currentClient.attributes( client().attributes(
forCharacterIndex: cursor, lineHeightRectangle: &lineHeightRect forCharacterIndex: cursor, lineHeightRectangle: &lineHeightRect
) )
cursor -= 1 cursor -= 1