ctlIME // Guard-let the event parameter in handle().
This commit is contained in:
parent
56581c0f8b
commit
50a5a83dbf
|
@ -15,7 +15,7 @@ extension ctlInputMethod {
|
||||||
/// 這樣分開處理很有必要,不然 handle() 函式會陷入無限迴圈。
|
/// 這樣分開處理很有必要,不然 handle() 函式會陷入無限迴圈。
|
||||||
/// - Parameter event: 由 IMK 選字窗接收的裝置操作輸入事件。
|
/// - Parameter event: 由 IMK 選字窗接收的裝置操作輸入事件。
|
||||||
/// - Returns: 回「`true`」以將該案件已攔截處理的訊息傳遞給 IMK;回「`false`」則放行、不作處理。
|
/// - Returns: 回「`true`」以將該案件已攔截處理的訊息傳遞給 IMK;回「`false`」則放行、不作處理。
|
||||||
func commonEventHandler(_ event: NSEvent!) -> Bool {
|
func commonEventHandler(_ event: NSEvent) -> Bool {
|
||||||
// 用 Shift 開關半形英數模式,僅對 macOS 10.15 及之後的 macOS 有效。
|
// 用 Shift 開關半形英數模式,僅對 macOS 10.15 及之後的 macOS 有效。
|
||||||
let shouldUseHandle =
|
let shouldUseHandle =
|
||||||
(IME.arrClientShiftHandlingExceptionList.contains(clientBundleIdentifier)
|
(IME.arrClientShiftHandlingExceptionList.contains(clientBundleIdentifier)
|
||||||
|
|
|
@ -197,18 +197,21 @@ class ctlInputMethod: IMKInputController {
|
||||||
|
|
||||||
/// 接受所有鍵鼠事件為 NSEvent,讓輸入法判斷是否要處理、該怎樣處理。
|
/// 接受所有鍵鼠事件為 NSEvent,讓輸入法判斷是否要處理、該怎樣處理。
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - event: 裝置操作輸入事件。
|
/// - event: 裝置操作輸入事件,可能會是 nil。
|
||||||
/// - sender: 呼叫了該函式的客體(無須使用)。
|
/// - sender: 呼叫了該函式的客體(無須使用)。
|
||||||
/// - Returns: 回「`true`」以將該案件已攔截處理的訊息傳遞給 IMK;回「`false`」則放行、不作處理。
|
/// - Returns: 回「`true`」以將該案件已攔截處理的訊息傳遞給 IMK;回「`false`」則放行、不作處理。
|
||||||
@objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
|
@objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
|
||||||
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
||||||
|
|
||||||
|
// 就這傳入的 NSEvent 都還有可能是 nil,Apple InputMethodKit 團隊到底在搞三小。
|
||||||
|
guard let event = event else { return false }
|
||||||
|
|
||||||
// IMK 選字窗處理,當且僅當啟用了 IMK 選字窗的時候才會生效。
|
// IMK 選字窗處理,當且僅當啟用了 IMK 選字窗的時候才會生效。
|
||||||
// 這樣可以讓 interpretKeyEvents() 函式自行判斷:
|
// 這樣可以讓 interpretKeyEvents() 函式自行判斷:
|
||||||
// - 是就地交給 super.interpretKeyEvents() 處理?
|
// - 是就地交給 super.interpretKeyEvents() 處理?
|
||||||
// - 還是藉由 delegate 扔回 ctlInputMethod 給 KeyHandler 處理?
|
// - 還是藉由 delegate 扔回 ctlInputMethod 給 KeyHandler 處理?
|
||||||
if let ctlCandidateCurrent = ctlInputMethod.ctlCandidateCurrent as? ctlCandidateIMK, ctlCandidateCurrent.visible {
|
if let ctlCandidateCurrent = ctlInputMethod.ctlCandidateCurrent as? ctlCandidateIMK, ctlCandidateCurrent.visible {
|
||||||
let event: NSEvent! = ctlCandidateIMK.replaceNumPadKeyCodes(target: event) ?? event
|
let event: NSEvent = ctlCandidateIMK.replaceNumPadKeyCodes(target: event) ?? event
|
||||||
let input = InputSignal(event: event)
|
let input = InputSignal(event: event)
|
||||||
// Shift+Enter 是個特殊情形,不提前攔截處理的話、會有垃圾參數傳給 delegate 的 keyHandler 從而崩潰。
|
// Shift+Enter 是個特殊情形,不提前攔截處理的話、會有垃圾參數傳給 delegate 的 keyHandler 從而崩潰。
|
||||||
// 所以這裡直接將 Shift Flags 清空。
|
// 所以這裡直接將 Shift Flags 清空。
|
||||||
|
|
|
@ -62,7 +62,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
|
||||||
/// 該函式僅由 IMK 選字窗來存取,且對接給 commonEventHandler()。
|
/// 該函式僅由 IMK 選字窗來存取,且對接給 commonEventHandler()。
|
||||||
/// - Parameter event: 由 IMK 選字窗接收的裝置操作輸入事件。
|
/// - Parameter event: 由 IMK 選字窗接收的裝置操作輸入事件。
|
||||||
/// - Returns: 回「`true`」以將該案件已攔截處理的訊息傳遞給 IMK;回「`false`」則放行、不作處理。
|
/// - Returns: 回「`true`」以將該案件已攔截處理的訊息傳遞給 IMK;回「`false`」則放行、不作處理。
|
||||||
@discardableResult func sharedEventHandler(_ event: NSEvent!) -> Bool {
|
@discardableResult func sharedEventHandler(_ event: NSEvent) -> Bool {
|
||||||
commonEventHandler(event)
|
commonEventHandler(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class CandidateKeyLabel: NSObject {
|
||||||
|
|
||||||
public protocol ctlCandidateDelegate: AnyObject {
|
public protocol ctlCandidateDelegate: AnyObject {
|
||||||
var isAssociatedPhrasesState: Bool { get }
|
var isAssociatedPhrasesState: Bool { get }
|
||||||
func sharedEventHandler(_ event: NSEvent!) -> Bool
|
func sharedEventHandler(_ event: NSEvent) -> Bool
|
||||||
func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int
|
func candidateCountForController(_ controller: ctlCandidateProtocol) -> Int
|
||||||
func candidatesForController(_ controller: ctlCandidateProtocol) -> [(String, String)]
|
func candidatesForController(_ controller: ctlCandidateProtocol) -> [(String, String)]
|
||||||
func ctlCandidate(_ controller: ctlCandidateProtocol, candidateAtIndex index: Int)
|
func ctlCandidate(_ controller: ctlCandidateProtocol, candidateAtIndex index: Int)
|
||||||
|
|
Loading…
Reference in New Issue