KeyHandler // _handleCandidateState: Add comments.

This commit is contained in:
ShikiSuen 2022-04-18 14:31:26 +08:00
parent 79f7299fd0
commit c632654672
1 changed files with 61 additions and 34 deletions

View File

@ -39,38 +39,35 @@ import Cocoa
let charCode: UniChar = input.charCode
let ctlCandidateCurrent = delegate!.ctlCandidate(for: self) as! ctlCandidate
// MARK: Cancel Candidate
let cancelCandidateKey =
input.isBackSpace || input.isESC || input.isDelete
|| ((input.isCursorBackward || input.isCursorForward) && input.isShiftHold)
if cancelCandidateKey {
if state is InputState.AssociatedPhrases {
clear()
let empty = InputState.EmptyIgnoringPreviousState()
stateCallback(empty)
} else if mgrPrefs.useSCPCTypingMode {
clear()
let empty = InputState.EmptyIgnoringPreviousState()
stateCallback(empty)
} else if isBuilderEmpty() {
if (state is InputState.AssociatedPhrases)
|| mgrPrefs.useSCPCTypingMode
|| isBuilderEmpty()
{
//
//
// 使 BackSpace
// isBuilderEmpty()
clear()
let empty = InputState.EmptyIgnoringPreviousState()
stateCallback(empty)
stateCallback(InputState.EmptyIgnoringPreviousState())
} else {
let inputting = buildInputtingState()
stateCallback(inputting)
stateCallback(buildInputtingState())
}
return true
}
// MARK: Enter
if input.isEnter {
if state is InputState.AssociatedPhrases {
clear()
let empty = InputState.EmptyIgnoringPreviousState()
stateCallback(empty)
stateCallback(InputState.EmptyIgnoringPreviousState())
return true
}
delegate!.keyHandler(
@ -81,10 +78,14 @@ import Cocoa
return true
}
// MARK: Tab
if input.isTab {
let updated: Bool =
mgrPrefs.specifyShiftTabKeyBehavior
? (input.isShiftHold ? ctlCandidateCurrent.showPreviousPage() : ctlCandidateCurrent.showNextPage())
? (input.isShiftHold
? ctlCandidateCurrent.showPreviousPage()
: ctlCandidateCurrent.showNextPage())
: (input.isShiftHold
? ctlCandidateCurrent.highlightPreviousCandidate()
: ctlCandidateCurrent.highlightNextCandidate())
@ -95,6 +96,8 @@ import Cocoa
return true
}
// MARK: Space
if input.isSpace {
let updated: Bool =
mgrPrefs.specifyShiftSpaceKeyBehavior
@ -111,6 +114,8 @@ import Cocoa
return true
}
// MARK: PgDn
if input.isPageDown || input.emacsKey == vChewingEmacsKey.nextPage {
let updated: Bool = ctlCandidateCurrent.showNextPage()
if !updated {
@ -120,6 +125,8 @@ import Cocoa
return true
}
// MARK: PgUp
if input.isPageUp {
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
if !updated {
@ -129,6 +136,8 @@ import Cocoa
return true
}
// MARK: Left Arrow
if input.isLeft {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
@ -146,6 +155,8 @@ import Cocoa
return true
}
// MARK: EmacsKey Backward
if input.emacsKey == vChewingEmacsKey.backward {
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
if !updated {
@ -155,6 +166,8 @@ import Cocoa
return true
}
// MARK: Right Arrow
if input.isRight {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
@ -172,6 +185,8 @@ import Cocoa
return true
}
// MARK: EmacsKey Forward
if input.emacsKey == vChewingEmacsKey.forward {
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
if !updated {
@ -181,6 +196,8 @@ import Cocoa
return true
}
// MARK: Up Arrow
if input.isUp {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
@ -198,6 +215,8 @@ import Cocoa
return true
}
// MARK: Down Arrow
if input.isDown {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.showNextPage()
@ -215,6 +234,8 @@ import Cocoa
return true
}
// MARK: Home Key
if input.isHome || input.emacsKey == vChewingEmacsKey.home {
if ctlCandidateCurrent.selectedCandidateIndex == 0 {
IME.prtDebugIntel("9B6EDE8D")
@ -234,6 +255,8 @@ import Cocoa
candidates = (state as! InputState.AssociatedPhrases).candidates
}
// MARK: End Key
if candidates.isEmpty {
return false
} else { // count > 0!isEmpty滿
@ -248,6 +271,8 @@ import Cocoa
}
}
// MARK: - Associated Phrases
if state is InputState.AssociatedPhrases {
if !input.isShiftHold { return false }
}
@ -276,6 +301,8 @@ import Cocoa
if state is InputState.AssociatedPhrases { return false }
// MARK: SCPC Mode Processing
if mgrPrefs.useSCPCTypingMode {
var punctuationNamePrefix = ""