diff --git a/Input Source/ClientManager.swift b/Input Source/ClientManager.swift index 47eff7e..4b5f89c 100644 --- a/Input Source/ClientManager.swift +++ b/Input Source/ClientManager.swift @@ -83,10 +83,10 @@ class ClientManager: CustomStringConvertible { } func getCandidateAt(_ index: Int) -> String? { - if candidates.count < index { - return nil - } else { + if candidates.count > index { return candidates[index] + } else { + return nil } } diff --git a/Input Source/VarnamController.swift b/Input Source/VarnamController.swift index a1717a4..a8f3efa 100644 --- a/Input Source/VarnamController.swift +++ b/Input Source/VarnamController.swift @@ -99,12 +99,17 @@ public class VarnamController: IMKInputController { } } - func commitCandidateAt(_ position: Int) { + func commitCandidateAt(_ position: Int) -> Bool { if position == 0 { - commitText(preedit) + if preedit.count > 0 { + commitText(preedit) + return true + } } else if let text = clientManager.getCandidateAt(position-1) { commitText(text) + return true } + return false } func commitPreedit() -> Bool { @@ -237,8 +242,7 @@ public class VarnamController: IMKInputController { if numericKey >= 0 && numericKey <= 9 { // Numeric key press - commitCandidateAt(numericKey) - return true + return commitCandidateAt(numericKey) } let charScalar = chars.unicodeScalars.first!