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_" }
// 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_")

View File

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

View File

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

View File

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

View File

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