KeyHandler // _handleCandidateState: Add comments.

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

View File

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