Skip to content

Commit

Permalink
Fix #8, varnam shouldn't crash when numbers are pressed (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
subins2000 authored Dec 18, 2021
1 parent 2ffdaef commit 3f26690
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Input Source/ClientManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
12 changes: 8 additions & 4 deletions Input Source/VarnamController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit 3f26690

Please sign in to comment.