InputHandler // Improve precision of handling modified flags.

This commit is contained in:
ShikiSuen 2024-01-29 21:17:55 +08:00
parent 4c45f4ddda
commit 24cf7e9971
5 changed files with 45 additions and 44 deletions

View File

@ -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_")

View File

@ -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

View File

@ -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
} }

View File

@ -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

View File

@ -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)