InputHandler // Improve precision of handling modified flags.
This commit is contained in:
parent
4c45f4ddda
commit
24cf7e9971
|
@ -585,7 +585,7 @@ public class InputHandler: InputHandlerProtocol {
|
|||
if prefs.halfWidthPunctuationEnabled { return "_half_punctuation_" }
|
||||
// 注意:這一行為 SHIFT+ALT+主鍵盤數字鍵專用,強制無視不同地區的鍵盤在這個按鍵組合下的符號輸入差異。
|
||||
// 但如果去掉「input.isMainAreaNumKey」這個限定條件的話,可能會影響其他依賴 Shift 鍵輸入的符號。
|
||||
if input.isMainAreaNumKey, input.keyModifierFlags == [.option, .shift] { return "_shift_alt_punctuation_" }
|
||||
if input.isMainAreaNumKey, input.commonKeyModifierFlags == [.option, .shift] { return "_shift_alt_punctuation_" }
|
||||
var result = ""
|
||||
switch (input.isControlHold, input.isOptionHold) {
|
||||
case (true, true): result.append("_alt_ctrl_punctuation_")
|
||||
|
|
|
@ -39,7 +39,7 @@ extension InputHandler {
|
|||
if candidates[highlightedIndex].keyArray.count < 2 || candidates[highlightedIndex].value.count < 2 {
|
||||
break manipulator
|
||||
}
|
||||
switch input.keyModifierFlags {
|
||||
switch input.commonKeyModifierFlags {
|
||||
case [.option, .command] where input.keyCode == 27: // 減號鍵
|
||||
ctlCandidate.delegate?.candidatePairRightClicked(at: highlightedIndex, action: .toNerf)
|
||||
return true
|
||||
|
@ -61,11 +61,11 @@ extension InputHandler {
|
|||
|
||||
// MARK: 取消選字 (Cancel Candidate)
|
||||
|
||||
let cancelCandidateKey =
|
||||
let dismissingCandidateWindow =
|
||||
input.isBackSpace || input.isEsc || input.isDelete
|
||||
|| ((input.isCursorBackward || input.isCursorForward) && input.isShiftHold)
|
||||
|| ((input.isCursorBackward || input.isCursorForward) && input.commonKeyModifierFlags == .shift)
|
||||
|
||||
if cancelCandidateKey {
|
||||
if dismissingCandidateWindow {
|
||||
if state.type == .ofAssociates
|
||||
|| prefs.useSCPCTypingMode
|
||||
|| compositor.isEmpty
|
||||
|
@ -77,7 +77,7 @@ extension InputHandler {
|
|||
delegate.switchState(IMEState.ofAbortion())
|
||||
} else {
|
||||
delegate.switchState(generateStateOfInputting())
|
||||
if input.isCursorBackward || input.isCursorForward, input.isShiftHold {
|
||||
if input.isCursorBackward || input.isCursorForward, input.commonKeyModifierFlags == .shift {
|
||||
return triageInput(event: input)
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ extension InputHandler {
|
|||
// 關聯詞語。
|
||||
associatedPhrases: if handleAssociates {
|
||||
guard handleAssociates else { break associatedPhrases }
|
||||
guard input.keyModifierFlags == .shift else { break associatedPhrases }
|
||||
guard input.commonKeyModifierFlags == .shift else { break associatedPhrases }
|
||||
let pair = Megrez.KeyValuePaired(
|
||||
keyArray: highlightedCandidate.keyArray, value: highlightedCandidate.value
|
||||
)
|
||||
|
@ -161,7 +161,6 @@ extension InputHandler {
|
|||
_ = ctlCandidate.showNextLine()
|
||||
default: break handleArrowKey
|
||||
}
|
||||
return true
|
||||
case .kHome:
|
||||
_ =
|
||||
(ctlCandidate.highlightedIndex == 0)
|
||||
|
@ -247,8 +246,8 @@ extension InputHandler {
|
|||
// MARK: - Flipping pages by using modified bracket keys (when they are not occupied).
|
||||
|
||||
// Shift+Command+[] 被 Chrome 系瀏覽器佔用,所以改用 Ctrl。
|
||||
let ctrlCMD: Bool = input.keyModifierFlags == [.control, .command]
|
||||
let ctrlShiftCMD: Bool = input.keyModifierFlags == [.control, .command, .shift]
|
||||
let ctrlCMD: Bool = input.commonKeyModifierFlags == [.control, .command]
|
||||
let ctrlShiftCMD: Bool = input.commonKeyModifierFlags == [.control, .command, .shift]
|
||||
if ctrlShiftCMD || ctrlCMD {
|
||||
// 此處 JIS 鍵盤判定無法用於螢幕鍵盤。所以,螢幕鍵盤的場合,系統會依照 US 鍵盤的判定方案。
|
||||
switch (input.keyCode, IMEApp.isKeyboardJIS) {
|
||||
|
@ -265,7 +264,7 @@ extension InputHandler {
|
|||
// MARK: - Flipping pages by using symbol menu keys (when they are not occupied).
|
||||
|
||||
if input.isSymbolMenuPhysicalKey {
|
||||
switch input.keyModifierFlags {
|
||||
switch input.commonKeyModifierFlags {
|
||||
case .shift, [],
|
||||
.option where state.type != .ofSymbolTable:
|
||||
var updated = true
|
||||
|
|
|
@ -363,7 +363,7 @@ extension InputHandler {
|
|||
|
||||
var displayedText = state.displayedText
|
||||
|
||||
if input.keyModifierFlags == [.option, .shift] {
|
||||
if input.commonKeyModifierFlags == [.option, .shift] {
|
||||
displayedText = displayedText.map(\.description).joined(separator: " ")
|
||||
} else if readingOnly {
|
||||
displayedText = commissionByCtrlCommandEnter()
|
||||
|
@ -376,7 +376,7 @@ extension InputHandler {
|
|||
delegate.switchState(IMEState.ofCommitting(textToCommit: displayedText))
|
||||
|
||||
associatedPhrases: if !prefs.useSCPCTypingMode, prefs.associatedPhrasesEnabled {
|
||||
guard input.keyModifierFlags == .shift else { break associatedPhrases }
|
||||
guard input.commonKeyModifierFlags == .shift else { break associatedPhrases }
|
||||
guard isComposerOrCalligrapherEmpty else { break associatedPhrases }
|
||||
let associatedCandidates = associatesData()
|
||||
guard !associatedCandidates.isEmpty else { break associatedPhrases }
|
||||
|
@ -478,7 +478,7 @@ extension InputHandler {
|
|||
delegate.switchState(updatedState)
|
||||
}
|
||||
strCodePointBuffer = strCodePointBuffer.dropLast(1).description
|
||||
if input.keyModifierFlags == .option {
|
||||
if input.commonKeyModifierFlags == .option {
|
||||
strCodePointBuffer.removeAll()
|
||||
refreshState()
|
||||
isCodePointInputMode = true
|
||||
|
@ -493,34 +493,36 @@ extension InputHandler {
|
|||
}
|
||||
|
||||
// 引入 macOS 內建注音輸入法的行為,允許用 Shift+BackSpace 解構前一個漢字的讀音。
|
||||
shiftBksp: switch prefs.specifyShiftBackSpaceKeyBehavior {
|
||||
case 0:
|
||||
if prefs.cassetteEnabled {
|
||||
guard input.isShiftHold, calligrapher.isEmpty else { break shiftBksp }
|
||||
guard let prevReading = previousParsableCalligraph else { break shiftBksp }
|
||||
compositor.dropKey(direction: .rear)
|
||||
walk() // 這裡必須 Walk 一次、來更新目前被 walk 的內容。
|
||||
calligrapher = prevReading
|
||||
} else {
|
||||
guard input.isShiftHold, isComposerOrCalligrapherEmpty else { break shiftBksp }
|
||||
guard let prevReading = previousParsableReading else { break shiftBksp }
|
||||
// prevReading 的內容分別是:「完整讀音」「去掉聲調的讀音」「是否有聲調」。
|
||||
compositor.dropKey(direction: .rear)
|
||||
walk() // 這裡必須 Walk 一次、來更新目前被 walk 的內容。
|
||||
prevReading.1.map(\.description).forEach { composer.receiveKey(fromPhonabet: $0) }
|
||||
shiftBksp: if input.commonKeyModifierFlags == .shift {
|
||||
switch prefs.specifyShiftBackSpaceKeyBehavior {
|
||||
case 0:
|
||||
if prefs.cassetteEnabled {
|
||||
guard input.isShiftHold, calligrapher.isEmpty else { break shiftBksp }
|
||||
guard let prevReading = previousParsableCalligraph else { break shiftBksp }
|
||||
compositor.dropKey(direction: .rear)
|
||||
walk() // 這裡必須 Walk 一次、來更新目前被 walk 的內容。
|
||||
calligrapher = prevReading
|
||||
} else {
|
||||
guard input.isShiftHold, isComposerOrCalligrapherEmpty else { break shiftBksp }
|
||||
guard let prevReading = previousParsableReading else { break shiftBksp }
|
||||
// prevReading 的內容分別是:「完整讀音」「去掉聲調的讀音」「是否有聲調」。
|
||||
compositor.dropKey(direction: .rear)
|
||||
walk() // 這裡必須 Walk 一次、來更新目前被 walk 的內容。
|
||||
prevReading.1.map(\.description).forEach { composer.receiveKey(fromPhonabet: $0) }
|
||||
}
|
||||
delegate.switchState(generateStateOfInputting())
|
||||
return true
|
||||
case 1:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
return true
|
||||
default: break
|
||||
}
|
||||
delegate.switchState(generateStateOfInputting())
|
||||
return true
|
||||
case 1:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
return true
|
||||
default: break
|
||||
}
|
||||
|
||||
let steps = getStepsToNearbyNodeBorder(direction: .rear)
|
||||
var actualSteps = 1
|
||||
|
||||
switch input.keyModifierFlags {
|
||||
switch input.commonKeyModifierFlags {
|
||||
case .shift:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
return true
|
||||
|
@ -539,7 +541,7 @@ extension InputHandler {
|
|||
}
|
||||
walk()
|
||||
} else {
|
||||
_ = input.keyModifierFlags == .option
|
||||
_ = input.commonKeyModifierFlags == .option
|
||||
? clearComposerAndCalligrapher()
|
||||
: letComposerAndCalligrapherDoBackSpace()
|
||||
}
|
||||
|
@ -578,11 +580,11 @@ extension InputHandler {
|
|||
|
||||
// macOS 認為 PC Delete 鍵訊號是必然有 .function 這個修飾鍵在起作用的。
|
||||
// 總之處理起來非常機車就是了。
|
||||
switch input.keyModifierFlags {
|
||||
case _ where input.isShiftHold && !input.isOptionHold && !input.isControlHold:
|
||||
switch input.commonKeyModifierFlags {
|
||||
case .shift:
|
||||
delegate.switchState(IMEState.ofAbortion())
|
||||
return true
|
||||
case _ where !input.isShiftHold && input.isOptionHold && !input.isControlHold:
|
||||
case .option:
|
||||
actualSteps = steps
|
||||
default: break
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public extension InputHandler {
|
|||
}
|
||||
case .kSymbolMenuPhysicalKeyJIS, .kSymbolMenuPhysicalKeyIntl:
|
||||
let isJIS = keyCodeType == .kSymbolMenuPhysicalKeyJIS
|
||||
switch input.keyModifierFlags {
|
||||
switch input.commonKeyModifierFlags {
|
||||
case []:
|
||||
return handlePunctuationList(alternative: false, isJIS: isJIS)
|
||||
case [.option, .shift]:
|
||||
|
@ -163,8 +163,8 @@ public extension InputHandler {
|
|||
|
||||
// Ctrl+Command+[] 輪替候選字。
|
||||
// Shift+Command+[] 被 Chrome 系瀏覽器佔用,所以改用 Ctrl。
|
||||
let ctrlCMD: Bool = input.keyModifierFlags == [.control, .command]
|
||||
let ctrlShiftCMD: Bool = input.keyModifierFlags == [.control, .command, .shift]
|
||||
let ctrlCMD: Bool = input.commonKeyModifierFlags == [.control, .command]
|
||||
let ctrlShiftCMD: Bool = input.commonKeyModifierFlags == [.control, .command, .shift]
|
||||
revolveCandidateWithBrackets: if ctrlShiftCMD || ctrlCMD {
|
||||
if state.type != .ofInputting { break revolveCandidateWithBrackets }
|
||||
// 此處 JIS 鍵盤判定無法用於螢幕鍵盤。所以,螢幕鍵盤的場合,系統會依照 US 鍵盤的判定方案。
|
||||
|
|
|
@ -166,7 +166,7 @@ public extension SessionCtl {
|
|||
}
|
||||
|
||||
// 準備修飾鍵,用來判定要新增的詞彙是否需要賦以非常低的權重。
|
||||
Self.areWeNerfing = eventToDeal.keyModifierFlags == [.shift, .command]
|
||||
Self.areWeNerfing = eventToDeal.commonKeyModifierFlags == [.shift, .command]
|
||||
|
||||
/// 直接交給 commonEventHandler 來處理。
|
||||
let result = inputHandler.triageInput(event: eventToDeal)
|
||||
|
|
Loading…
Reference in New Issue