Repo // Optimizing IMKCandidates experiences with SCPC mode.
This commit is contained in:
parent
ca98961e45
commit
a5b061e2fc
|
@ -235,6 +235,25 @@ class ctlInputMethod: IMKInputController {
|
||||||
ctlCandidateCurrent.interpretKeyEvents([newEvent])
|
ctlCandidateCurrent.interpretKeyEvents([newEvent])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let newChar = ctlCandidateIMK.defaultIMKSelectionKey[event.keyCode], input.isShiftHold,
|
||||||
|
isAssociatedPhrasesState
|
||||||
|
{
|
||||||
|
let newEvent = NSEvent.keyEvent(
|
||||||
|
with: event.type,
|
||||||
|
location: event.locationInWindow,
|
||||||
|
modifierFlags: [],
|
||||||
|
timestamp: event.timestamp,
|
||||||
|
windowNumber: event.windowNumber,
|
||||||
|
context: nil,
|
||||||
|
characters: newChar,
|
||||||
|
charactersIgnoringModifiers: event.charactersIgnoringModifiers ?? event.characters ?? "",
|
||||||
|
isARepeat: event.isARepeat,
|
||||||
|
keyCode: event.keyCode
|
||||||
|
)
|
||||||
|
ctlCandidateCurrent.perform(Selector(("handleKeyboardEvent:")), with: newEvent)
|
||||||
|
}
|
||||||
|
|
||||||
ctlCandidateCurrent.interpretKeyEvents([event])
|
ctlCandidateCurrent.interpretKeyEvents([event])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import InputMethodKit
|
||||||
|
|
||||||
public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
|
public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
|
||||||
public var currentLayout: CandidateLayout = .horizontal
|
public var currentLayout: CandidateLayout = .horizontal
|
||||||
private let defaultIMKSelectionKey: [UInt16: String] = [
|
public static let defaultIMKSelectionKey: [UInt16: String] = [
|
||||||
18: "1", 19: "2", 20: "3", 21: "4", 23: "5", 22: "6", 26: "7", 28: "8", 25: "9",
|
18: "1", 19: "2", 20: "3", 21: "4", 23: "5", 22: "6", 26: "7", 28: "8", 25: "9",
|
||||||
]
|
]
|
||||||
public weak var delegate: ctlCandidateDelegate? {
|
public weak var delegate: ctlCandidateDelegate? {
|
||||||
|
@ -241,7 +241,6 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
|
||||||
// 鬼知道為什麼這個函式接收的參數是陣列,但經過測試卻發現這個函式收到的陣列往往內容只有一個。
|
// 鬼知道為什麼這個函式接收的參數是陣列,但經過測試卻發現這個函式收到的陣列往往內容只有一個。
|
||||||
// 這也可能是 Objective-C 當中允許接收內容為 nil 的一種方式。
|
// 這也可能是 Objective-C 當中允許接收內容為 nil 的一種方式。
|
||||||
guard !eventArray.isEmpty else { return }
|
guard !eventArray.isEmpty else { return }
|
||||||
var eventArray = eventArray
|
|
||||||
let event = eventArray[0]
|
let event = eventArray[0]
|
||||||
let input = InputSignal(event: event)
|
let input = InputSignal(event: event)
|
||||||
guard let delegate = delegate else { return }
|
guard let delegate = delegate else { return }
|
||||||
|
@ -279,7 +278,7 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let newChar = defaultIMKSelectionKey[event.keyCode] {
|
if let newChar = ctlCandidateIMK.defaultIMKSelectionKey[event.keyCode] {
|
||||||
/// 根據 KeyCode 重新換算一下選字鍵的 NSEvent,糾正其 Character 數值。
|
/// 根據 KeyCode 重新換算一下選字鍵的 NSEvent,糾正其 Character 數值。
|
||||||
/// 反正 IMK 選字窗目前也沒辦法修改選字鍵。
|
/// 反正 IMK 選字窗目前也沒辦法修改選字鍵。
|
||||||
let newEvent = NSEvent.keyEvent(
|
let newEvent = NSEvent.keyEvent(
|
||||||
|
@ -295,13 +294,18 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
|
||||||
keyCode: event.keyCode
|
keyCode: event.keyCode
|
||||||
)
|
)
|
||||||
if let newEvent = newEvent {
|
if let newEvent = newEvent {
|
||||||
/// 這裡不用診斷了,檢出的內容都是經過轉換之後的正確 NSEvent。
|
if mgrPrefs.useSCPCTypingMode, delegate.isAssociatedPhrasesState {
|
||||||
eventArray = Array(eventArray.dropFirst(0))
|
// 註:input.isShiftHold 已經在 ctlInputMethod.handle() 內處理,因為在那邊處理才有效。
|
||||||
eventArray.insert(newEvent, at: 0)
|
if !input.isShiftHold {
|
||||||
|
_ = delegate.sharedEventHandler(event)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
perform(Selector(("handleKeyboardEvent:")), with: newEvent)
|
perform(Selector(("handleKeyboardEvent:")), with: newEvent)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if mgrPrefs.useSCPCTypingMode {
|
if mgrPrefs.useSCPCTypingMode {
|
||||||
if !input.isReservedKey {
|
if !input.isReservedKey {
|
||||||
|
|
Loading…
Reference in New Issue