KeyHandler // Refactoring a little.

This commit is contained in:
ShikiSuen 2022-05-13 12:32:25 +08:00
parent b64e48239e
commit f31373a104
2 changed files with 26 additions and 31 deletions

View File

@ -84,7 +84,6 @@ class KeyHandler: NSObject {
_walkedNodes.removeAll()
}
// ObjC 使
func setInputMode(_ value: String) {
// isKindOfClass
// plist
@ -122,7 +121,7 @@ class KeyHandler: NSObject {
let walker = Megrez.Walker(grid: _builder.grid())
// the reverse walk traces the grid from the end
let walked: [Megrez.NodeAnchor] = walker.reverseWalk(at: _builder.grid().width(), nodesLimit: 3, balanced: true)
let walked = walker.reverseWalk(at: _builder.grid().width(), nodesLimit: 3, balanced: true)
// then we use ".reversed()" to reverse the nodes so that we get the forward-walked nodes
_walkedNodes.removeAll()

View File

@ -37,12 +37,10 @@ extension KeyHandler {
) -> Bool {
let charCode: UniChar = input.charCode
var state = state // Turn this incoming constant into variable.
let inputText: String = input.inputText ?? ""
// Ignore the input if its inputText is empty.
// Reason: such inputs may be functional key combinations.
if inputText.isEmpty {
guard let inputText: String = input.inputText, !inputText.isEmpty else {
return false
}
@ -238,8 +236,7 @@ extension KeyHandler {
// MARK: Calling candidate window using Space or Down or PageUp / PageDn.
if let currentState = state as? InputState.NotEmpty {
if _composer.isEmpty,
if let currentState = state as? InputState.NotEmpty, _composer.isEmpty,
input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse || input.isSpace
|| input.isPageDown || input.isPageUp || input.isTab
|| (input.useVerticalMode && (input.isVerticalModeOnlyChooseCandidateKey))
@ -249,7 +246,7 @@ extension KeyHandler {
if input.isShiftHold || !mgrPrefs.chooseCandidateUsingSpace {
if getBuilderCursorIndex() >= getBuilderLength() {
let composingBuffer = currentState.composingBuffer
if (composingBuffer.count) != 0 {
if !composingBuffer.isEmpty {
stateCallback(InputState.Committing(poppedText: composingBuffer))
}
clear()
@ -268,7 +265,6 @@ extension KeyHandler {
stateCallback(buildCandidate(state: currentState, useVerticalMode: input.useVerticalMode))
return true
}
}
// MARK: -