Skip to content

Commit ab1db6c

Browse files
ecstasoylotem
authored andcommitted
fix(SquirrelInputController): no index offset to an empty string (#1045)
1 parent 1a70873 commit ab1db6c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

sources/SquirrelInputController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,12 @@ private extension SquirrelInputController {
470470
} else if end < preedit.endIndex && caretPos <= start {
471471
candidatePreview = String(candidatePreview[..<candidatePreview.index(candidatePreview.endIndex, offsetBy: -min(candidatePreview.count, max(0, preedit.distance(from: end, to: preedit.endIndex))))])
472472
}
473+
474+
let selStart = candidatePreview.isEmpty ? 0 : start.utf16Offset(in: candidatePreview)
475+
let selLength = candidatePreview.utf16.count - selStart
476+
473477
show(preedit: candidatePreview,
474-
selRange: NSRange(location: start.utf16Offset(in: candidatePreview), length: candidatePreview.utf16.distance(from: start, to: candidatePreview.endIndex)),
478+
selRange: NSRange(location: selStart, length: selLength),
475479
caretPos: candidatePreview.utf16.count)
476480
}
477481
} else {

0 commit comments

Comments
 (0)