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