KeyHandler // Reducing the usage of "as!", etc.

This commit is contained in:
ShikiSuen 2022-04-19 13:08:08 +08:00
parent 0ba02d3f11
commit c1ed41cf16
3 changed files with 366 additions and 358 deletions

View File

@ -2,27 +2,27 @@
// Refactored from the ObjCpp-version of this class by:
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
1. The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2. No trademark license is granted to use the trade names, trademarks, service
marks, or product names of Contributor, except as required to fulfill notice
requirements above.
2. No trademark license is granted to use the trade names, trademarks, service
marks, or product names of Contributor, except as required to fulfill notice
requirements above.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import Cocoa
@ -37,322 +37,327 @@ import Cocoa
) -> Bool {
let inputText = input.inputText
let charCode: UniChar = input.charCode
let ctlCandidateCurrent = delegate!.ctlCandidate(for: self) as! ctlCandidate
if let ctlCandidateCurrent = delegate!.ctlCandidate(for: self) as? ctlCandidate {
// MARK: Cancel Candidate
// MARK: Cancel Candidate
let cancelCandidateKey =
input.isBackSpace || input.isESC || input.isDelete
|| ((input.isCursorBackward || input.isCursorForward) && input.isShiftHold)
let cancelCandidateKey =
input.isBackSpace || input.isESC || input.isDelete
|| ((input.isCursorBackward || input.isCursorForward) && input.isShiftHold)
if cancelCandidateKey {
if (state is InputState.AssociatedPhrases)
|| mgrPrefs.useSCPCTypingMode
|| isBuilderEmpty()
{
//
//
// 使 BackSpace
// isBuilderEmpty()
clear()
stateCallback(InputState.EmptyIgnoringPreviousState())
} else {
stateCallback(buildInputtingState())
}
return true
}
// MARK: Enter
if input.isEnter {
if state is InputState.AssociatedPhrases {
clear()
stateCallback(InputState.EmptyIgnoringPreviousState())
if cancelCandidateKey {
if (state is InputState.AssociatedPhrases)
|| mgrPrefs.useSCPCTypingMode
|| isBuilderEmpty()
{
//
//
// 使 BackSpace
// isBuilderEmpty()
clear()
stateCallback(InputState.EmptyIgnoringPreviousState())
} else {
stateCallback(buildInputtingState())
}
return true
}
delegate!.keyHandler(
self,
didSelectCandidateAt: Int(ctlCandidateCurrent.selectedCandidateIndex),
ctlCandidate: ctlCandidateCurrent
)
return true
}
// MARK: Tab
// MARK: Enter
if input.isTab {
let updated: Bool =
mgrPrefs.specifyShiftTabKeyBehavior
? (input.isShiftHold
? ctlCandidateCurrent.showPreviousPage()
: ctlCandidateCurrent.showNextPage())
: (input.isShiftHold
? ctlCandidateCurrent.highlightPreviousCandidate()
: ctlCandidateCurrent.highlightNextCandidate())
if !updated {
IME.prtDebugIntel("9B691919")
errorCallback()
if input.isEnter {
if state is InputState.AssociatedPhrases {
clear()
stateCallback(InputState.EmptyIgnoringPreviousState())
return true
}
delegate!.keyHandler(
self,
didSelectCandidateAt: Int(ctlCandidateCurrent.selectedCandidateIndex),
ctlCandidate: ctlCandidateCurrent
)
return true
}
return true
}
// MARK: Space
// MARK: Tab
if input.isSpace {
let updated: Bool =
mgrPrefs.specifyShiftSpaceKeyBehavior
? (input.isShiftHold
? ctlCandidateCurrent.highlightNextCandidate()
: ctlCandidateCurrent.showNextPage())
: (input.isShiftHold
? ctlCandidateCurrent.showNextPage()
: ctlCandidateCurrent.highlightNextCandidate())
if !updated {
IME.prtDebugIntel("A11C781F")
errorCallback()
}
return true
}
// MARK: PgDn
if input.isPageDown || input.emacsKey == vChewingEmacsKey.nextPage {
let updated: Bool = ctlCandidateCurrent.showNextPage()
if !updated {
IME.prtDebugIntel("9B691919")
errorCallback()
}
return true
}
// MARK: PgUp
if input.isPageUp {
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
if !updated {
IME.prtDebugIntel("9569955D")
errorCallback()
}
return true
}
// MARK: Left Arrow
if input.isLeft {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
if input.isTab {
let updated: Bool =
mgrPrefs.specifyShiftTabKeyBehavior
? (input.isShiftHold
? ctlCandidateCurrent.showPreviousPage()
: ctlCandidateCurrent.showNextPage())
: (input.isShiftHold
? ctlCandidateCurrent.highlightPreviousCandidate()
: ctlCandidateCurrent.highlightNextCandidate())
if !updated {
IME.prtDebugIntel("1145148D")
IME.prtDebugIntel("9B691919")
errorCallback()
}
} else {
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
return true
}
// MARK: Space
if input.isSpace {
let updated: Bool =
mgrPrefs.specifyShiftSpaceKeyBehavior
? (input.isShiftHold
? ctlCandidateCurrent.highlightNextCandidate()
: ctlCandidateCurrent.showNextPage())
: (input.isShiftHold
? ctlCandidateCurrent.showNextPage()
: ctlCandidateCurrent.highlightNextCandidate())
if !updated {
IME.prtDebugIntel("1919810D")
IME.prtDebugIntel("A11C781F")
errorCallback()
}
return true
}
return true
}
// MARK: EmacsKey Backward
// MARK: PgDn
if input.emacsKey == vChewingEmacsKey.backward {
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
if !updated {
IME.prtDebugIntel("9B89308D")
errorCallback()
}
return true
}
// MARK: Right Arrow
if input.isRight {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
if !updated {
IME.prtDebugIntel("9B65138D")
errorCallback()
}
} else {
if input.isPageDown || input.emacsKey == vChewingEmacsKey.nextPage {
let updated: Bool = ctlCandidateCurrent.showNextPage()
if !updated {
IME.prtDebugIntel("9244908D")
IME.prtDebugIntel("9B691919")
errorCallback()
}
return true
}
return true
}
// MARK: EmacsKey Forward
// MARK: PgUp
if input.emacsKey == vChewingEmacsKey.forward {
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
if !updated {
IME.prtDebugIntel("9B2428D")
errorCallback()
}
return true
}
// MARK: Up Arrow
if input.isUp {
if ctlCandidateCurrent is ctlCandidateHorizontal {
if input.isPageUp {
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
if !updated {
IME.prtDebugIntel("9B614524")
IME.prtDebugIntel("9569955D")
errorCallback()
}
} else {
return true
}
// MARK: Left Arrow
if input.isLeft {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
if !updated {
IME.prtDebugIntel("1145148D")
errorCallback()
}
} else {
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
if !updated {
IME.prtDebugIntel("1919810D")
errorCallback()
}
}
return true
}
// MARK: EmacsKey Backward
if input.emacsKey == vChewingEmacsKey.backward {
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
if !updated {
IME.prtDebugIntel("ASD9908D")
IME.prtDebugIntel("9B89308D")
errorCallback()
}
return true
}
return true
}
// MARK: Down Arrow
// MARK: Right Arrow
if input.isDown {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.showNextPage()
if !updated {
IME.prtDebugIntel("92B990DD")
errorCallback()
if input.isRight {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
if !updated {
IME.prtDebugIntel("9B65138D")
errorCallback()
}
} else {
let updated: Bool = ctlCandidateCurrent.showNextPage()
if !updated {
IME.prtDebugIntel("9244908D")
errorCallback()
}
}
} else {
return true
}
// MARK: EmacsKey Forward
if input.emacsKey == vChewingEmacsKey.forward {
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
if !updated {
IME.prtDebugIntel("6B99908D")
IME.prtDebugIntel("9B2428D")
errorCallback()
}
}
return true
}
// MARK: Home Key
if input.isHome || input.emacsKey == vChewingEmacsKey.home {
if ctlCandidateCurrent.selectedCandidateIndex == 0 {
IME.prtDebugIntel("9B6EDE8D")
errorCallback()
} else {
ctlCandidateCurrent.selectedCandidateIndex = 0
return true
}
return true
}
// MARK: Up Arrow
var candidates: [String]!
if input.isUp {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.showPreviousPage()
if !updated {
IME.prtDebugIntel("9B614524")
errorCallback()
}
} else {
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
if !updated {
IME.prtDebugIntel("ASD9908D")
errorCallback()
}
}
return true
}
if state is InputState.ChoosingCandidate {
candidates = (state as! InputState.ChoosingCandidate).candidates
} else if state is InputState.AssociatedPhrases {
candidates = (state as! InputState.AssociatedPhrases).candidates
}
// MARK: Down Arrow
// MARK: End Key
if input.isDown {
if ctlCandidateCurrent is ctlCandidateHorizontal {
let updated: Bool = ctlCandidateCurrent.showNextPage()
if !updated {
IME.prtDebugIntel("92B990DD")
errorCallback()
}
} else {
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
if !updated {
IME.prtDebugIntel("6B99908D")
errorCallback()
}
}
return true
}
if candidates.isEmpty {
return false
} else { // count > 0!isEmpty滿
if input.isEnd || input.emacsKey == vChewingEmacsKey.end {
if ctlCandidateCurrent.selectedCandidateIndex == UInt(candidates.count - 1) {
IME.prtDebugIntel("9B69AAAD")
// MARK: Home Key
if input.isHome || input.emacsKey == vChewingEmacsKey.home {
if ctlCandidateCurrent.selectedCandidateIndex == 0 {
IME.prtDebugIntel("9B6EDE8D")
errorCallback()
} else {
ctlCandidateCurrent.selectedCandidateIndex = UInt(candidates.count - 1)
ctlCandidateCurrent.selectedCandidateIndex = 0
}
return true
}
}
// MARK: - Associated Phrases
// MARK: End Key
if state is InputState.AssociatedPhrases {
if !input.isShiftHold { return false }
}
var candidates: [String]!
var index: Int = NSNotFound
var match: String!
if state is InputState.AssociatedPhrases { match = input.inputTextIgnoringModifiers } else { match = inputText }
var j = 0
while j < ctlCandidateCurrent.keyLabels.count {
let label: CandidateKeyLabel = ctlCandidateCurrent.keyLabels[j]
if match.compare(label.key, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
index = j
break
if let state = state as? InputState.ChoosingCandidate {
candidates = state.candidates
} else if let state = state as? InputState.AssociatedPhrases {
candidates = state.candidates
}
j += 1
}
if index != NSNotFound {
let candidateIndex: UInt = ctlCandidateCurrent.candidateIndexAtKeyLabelIndex(UInt(index))
if candidateIndex != UInt.max {
delegate!.keyHandler(self, didSelectCandidateAt: Int(candidateIndex), ctlCandidate: ctlCandidateCurrent)
return true
if candidates.isEmpty {
return false
} else { // count > 0!isEmpty滿
if input.isEnd || input.emacsKey == vChewingEmacsKey.end {
if ctlCandidateCurrent.selectedCandidateIndex == UInt(candidates.count - 1) {
IME.prtDebugIntel("9B69AAAD")
errorCallback()
} else {
ctlCandidateCurrent.selectedCandidateIndex = UInt(candidates.count - 1)
}
}
}
}
if state is InputState.AssociatedPhrases { return false }
// MARK: - Associated Phrases
// MARK: SCPC Mode Processing
if state is InputState.AssociatedPhrases {
if !input.isShiftHold { return false }
}
if mgrPrefs.useSCPCTypingMode {
var punctuationNamePrefix = ""
if input.isOptionHold {
punctuationNamePrefix = "_alt_punctuation_"
} else if input.isControlHold {
punctuationNamePrefix = "_ctrl_punctuation_"
} else if mgrPrefs.halfWidthPunctuationEnabled {
punctuationNamePrefix = "_half_punctuation_"
var index: Int = NSNotFound
var match: String!
if state is InputState.AssociatedPhrases {
match = input.inputTextIgnoringModifiers
} else {
punctuationNamePrefix = "_punctuation_"
match = inputText
}
let parser = getCurrentMandarinParser()
let arrCustomPunctuations: [String] = [
punctuationNamePrefix, parser, String(format: "%c", CChar(charCode)),
]
let customPunctuation: String = arrCustomPunctuations.joined(separator: "")
let arrPunctuations: [String] = [punctuationNamePrefix, String(format: "%c", CChar(charCode))]
let punctuation: String = arrPunctuations.joined(separator: "")
var shouldAutoSelectCandidate: Bool =
chkKeyValidity(charCode) || ifLangModelHasUnigrams(forKey: customPunctuation)
|| ifLangModelHasUnigrams(forKey: punctuation)
if !shouldAutoSelectCandidate, input.isUpperCaseASCIILetterKey {
let letter: String! = String(format: "%@%c", "_letter_", CChar(charCode))
if ifLangModelHasUnigrams(forKey: letter) { shouldAutoSelectCandidate = true }
var j = 0
while j < ctlCandidateCurrent.keyLabels.count {
let label: CandidateKeyLabel = ctlCandidateCurrent.keyLabels[j]
if match.compare(label.key, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
index = j
break
}
j += 1
}
if shouldAutoSelectCandidate {
let candidateIndex: UInt = ctlCandidateCurrent.candidateIndexAtKeyLabelIndex(0)
if index != NSNotFound {
let candidateIndex: UInt = ctlCandidateCurrent.candidateIndexAtKeyLabelIndex(UInt(index))
if candidateIndex != UInt.max {
delegate!.keyHandler(
self,
didSelectCandidateAt: Int(candidateIndex),
ctlCandidate: ctlCandidateCurrent
)
clear()
let empty = InputState.EmptyIgnoringPreviousState()
stateCallback(empty)
return handle(
input: input, state: empty, stateCallback: stateCallback, errorCallback: errorCallback
self, didSelectCandidateAt: Int(candidateIndex), ctlCandidate: ctlCandidateCurrent
)
return true
}
return true
}
}
if state is InputState.AssociatedPhrases { return false }
// MARK: SCPC Mode Processing
if mgrPrefs.useSCPCTypingMode {
var punctuationNamePrefix = ""
if input.isOptionHold {
punctuationNamePrefix = "_alt_punctuation_"
} else if input.isControlHold {
punctuationNamePrefix = "_ctrl_punctuation_"
} else if mgrPrefs.halfWidthPunctuationEnabled {
punctuationNamePrefix = "_half_punctuation_"
} else {
punctuationNamePrefix = "_punctuation_"
}
let parser = getCurrentMandarinParser()
let arrCustomPunctuations: [String] = [
punctuationNamePrefix, parser, String(format: "%c", CChar(charCode)),
]
let customPunctuation: String = arrCustomPunctuations.joined(separator: "")
let arrPunctuations: [String] = [punctuationNamePrefix, String(format: "%c", CChar(charCode))]
let punctuation: String = arrPunctuations.joined(separator: "")
var shouldAutoSelectCandidate: Bool =
chkKeyValidity(charCode) || ifLangModelHasUnigrams(forKey: customPunctuation)
|| ifLangModelHasUnigrams(forKey: punctuation)
if !shouldAutoSelectCandidate, input.isUpperCaseASCIILetterKey {
let letter: String! = String(format: "%@%c", "_letter_", CChar(charCode))
if ifLangModelHasUnigrams(forKey: letter) { shouldAutoSelectCandidate = true }
}
if shouldAutoSelectCandidate {
let candidateIndex: UInt = ctlCandidateCurrent.candidateIndexAtKeyLabelIndex(0)
if candidateIndex != UInt.max {
delegate!.keyHandler(
self,
didSelectCandidateAt: Int(candidateIndex),
ctlCandidate: ctlCandidateCurrent
)
clear()
let empty = InputState.EmptyIgnoringPreviousState()
stateCallback(empty)
return handle(
input: input, state: empty, stateCallback: stateCallback, errorCallback: errorCallback
)
}
return true
}
}
} // END: "if let ctlCandidateCurrent"
IME.prtDebugIntel("172A0F81")
errorCallback()

View File

@ -125,16 +125,13 @@ import Cocoa
// MARK: Handle Marking.
if state is InputState.Marking {
let marking = state as! InputState.Marking
if let marking = state as? InputState.Marking {
if _handleMarkingState(
state as! InputState.Marking, input: input, stateCallback: stateCallback,
marking, input: input, stateCallback: stateCallback,
errorCallback: errorCallback
) {
return true
}
state = marking.convertToInputting()
stateCallback(state)
}
@ -224,41 +221,43 @@ import Cocoa
// MARK: Calling candidate window using Space or Down or PageUp / PageDn.
if isPhoneticReadingBufferEmpty() && (state is InputState.NotEmpty)
&& (input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse || input.isSpace
|| input.isPageDown || input.isPageUp || input.isTab
|| (input.useVerticalMode && (input.isVerticalModeOnlyChooseCandidateKey)))
{
if input.isSpace {
// If the Space key is NOT set to be a selection key
if input.isShiftHold || !mgrPrefs.chooseCandidateUsingSpace {
if getBuilderCursorIndex() >= getBuilderLength() {
let composingBuffer = (state as! InputState.NotEmpty).composingBuffer
if (composingBuffer.count) != 0 {
let committing = InputState.Committing(poppedText: composingBuffer)
if let currentState = state as? InputState.NotEmpty {
if isPhoneticReadingBufferEmpty(),
input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse || input.isSpace
|| input.isPageDown || input.isPageUp || input.isTab
|| (input.useVerticalMode && (input.isVerticalModeOnlyChooseCandidateKey))
{
if input.isSpace {
// If the Space key is NOT set to be a selection key
if input.isShiftHold || !mgrPrefs.chooseCandidateUsingSpace {
if getBuilderCursorIndex() >= getBuilderLength() {
let composingBuffer = currentState.composingBuffer
if (composingBuffer.count) != 0 {
let committing = InputState.Committing(poppedText: composingBuffer)
stateCallback(committing)
}
clear()
let committing = InputState.Committing(poppedText: " ")
stateCallback(committing)
let empty = InputState.Empty()
stateCallback(empty)
} else if ifLangModelHasUnigrams(forKey: " ") {
insertReadingToBuilder(atCursor: " ")
let poppedText = _popOverflowComposingTextAndWalk()
let inputting = buildInputtingState()
inputting.poppedText = poppedText
stateCallback(inputting)
}
clear()
let committing = InputState.Committing(poppedText: " ")
stateCallback(committing)
let empty = InputState.Empty()
stateCallback(empty)
} else if ifLangModelHasUnigrams(forKey: " ") {
insertReadingToBuilder(atCursor: " ")
let poppedText = _popOverflowComposingTextAndWalk()
let inputting = buildInputtingState()
inputting.poppedText = poppedText
stateCallback(inputting)
return true
}
return true
}
let choosingCandidates = _buildCandidateState(
currentState,
useVerticalMode: input.useVerticalMode
)
stateCallback(choosingCandidates)
return true
}
let choosingCandidates = _buildCandidateState(
state as! InputState.NotEmpty,
useVerticalMode: input.useVerticalMode
)
stateCallback(choosingCandidates)
return true
}
// MARK: -

View File

@ -228,11 +228,13 @@ import Cocoa
clear()
let current = state as! InputState.Inputting
let composingBuffer = current.composingBuffer
if let current = state as? InputState.Inputting {
let composingBuffer = current.composingBuffer
let committing = InputState.Committing(poppedText: composingBuffer)
stateCallback(committing)
}
let committing = InputState.Committing(poppedText: composingBuffer)
stateCallback(committing)
let empty = InputState.Empty()
stateCallback(empty)
return true
@ -468,37 +470,38 @@ import Cocoa
return true
}
let currentState = state as! InputState.Inputting
if input.isShiftHold {
// Shift + Right
if currentState.cursorIndex < (currentState.composingBuffer as NSString).length {
let nextPosition = (currentState.composingBuffer as NSString).nextUtf16Position(
for: Int(currentState.cursorIndex))
let marking: InputState.Marking! = InputState.Marking(
composingBuffer: currentState.composingBuffer,
cursorIndex: currentState.cursorIndex,
markerIndex: UInt(nextPosition),
readings: _currentReadings()
)
marking.tooltipForInputting = currentState.tooltip
stateCallback(marking)
if let currentState = state as? InputState.Inputting {
if input.isShiftHold {
// Shift + Right
if currentState.cursorIndex < (currentState.composingBuffer as NSString).length {
let nextPosition = (currentState.composingBuffer as NSString).nextUtf16Position(
for: Int(currentState.cursorIndex))
let marking: InputState.Marking! = InputState.Marking(
composingBuffer: currentState.composingBuffer,
cursorIndex: currentState.cursorIndex,
markerIndex: UInt(nextPosition),
readings: _currentReadings()
)
marking.tooltipForInputting = currentState.tooltip
stateCallback(marking)
} else {
IME.prtDebugIntel("BB7F6DB9")
errorCallback()
stateCallback(state)
}
} else {
IME.prtDebugIntel("BB7F6DB9")
errorCallback()
stateCallback(state)
}
} else {
if getBuilderCursorIndex() < getBuilderLength() {
setBuilderCursorIndex(getBuilderCursorIndex() + 1)
let inputting = buildInputtingState()
stateCallback(inputting)
} else {
IME.prtDebugIntel("A96AAD58")
errorCallback()
stateCallback(state)
if getBuilderCursorIndex() < getBuilderLength() {
setBuilderCursorIndex(getBuilderCursorIndex() + 1)
let inputting = buildInputtingState()
stateCallback(inputting)
} else {
IME.prtDebugIntel("A96AAD58")
errorCallback()
stateCallback(state)
}
}
}
return true
}
@ -519,37 +522,38 @@ import Cocoa
return true
}
let currentState = state as! InputState.Inputting
if input.isShiftHold {
// Shift + left
if currentState.cursorIndex > 0 {
let previousPosition = (currentState.composingBuffer as NSString).previousUtf16Position(
for: Int(currentState.cursorIndex))
let marking: InputState.Marking! = InputState.Marking(
composingBuffer: currentState.composingBuffer,
cursorIndex: currentState.cursorIndex,
markerIndex: UInt(previousPosition),
readings: _currentReadings()
)
marking.tooltipForInputting = currentState.tooltip
stateCallback(marking)
if let currentState = state as? InputState.Inputting {
if input.isShiftHold {
// Shift + left
if currentState.cursorIndex > 0 {
let previousPosition = (currentState.composingBuffer as NSString).previousUtf16Position(
for: Int(currentState.cursorIndex))
let marking: InputState.Marking! = InputState.Marking(
composingBuffer: currentState.composingBuffer,
cursorIndex: currentState.cursorIndex,
markerIndex: UInt(previousPosition),
readings: _currentReadings()
)
marking.tooltipForInputting = currentState.tooltip
stateCallback(marking)
} else {
IME.prtDebugIntel("D326DEA3")
errorCallback()
stateCallback(state)
}
} else {
IME.prtDebugIntel("D326DEA3")
errorCallback()
stateCallback(state)
}
} else {
if getBuilderCursorIndex() > 0 {
setBuilderCursorIndex(getBuilderCursorIndex() - 1)
let inputting = buildInputtingState()
stateCallback(inputting)
} else {
IME.prtDebugIntel("7045E6F3")
errorCallback()
stateCallback(state)
if getBuilderCursorIndex() > 0 {
setBuilderCursorIndex(getBuilderCursorIndex() - 1)
let inputting = buildInputtingState()
stateCallback(inputting)
} else {
IME.prtDebugIntel("7045E6F3")
errorCallback()
stateCallback(state)
}
}
}
return true
}
}