Skip to content

Commit

Permalink
Fix string.index crash due to emojis (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong committed Jul 31, 2023
1 parent 99965ff commit 7541680
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class EditorModuleCompletion: NativeModuleCompletion {
let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = anchor.text

let pos = anchor.text.index(anchor.text.startIndex, offsetBy: max(0, anchor.pos - 1))
let pos = anchor.text.utf16.index(anchor.text.startIndex, offsetBy: max(0, anchor.pos - 1))
let range = tokenizer.tokenRange(at: pos)

// Figure out the partial word range with one tokenization pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class EditorModuleTokenizer: NativeModuleTokenizer {
let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = anchor.text

let pos = anchor.text.index(anchor.text.startIndex, offsetBy: anchor.pos)
let pos = anchor.text.utf16.index(anchor.text.startIndex, offsetBy: anchor.pos)
let bounds = bounds(in: tokenizer.tokenRange(at: pos), text: anchor.text)

// Always select at least one character
Expand Down

0 comments on commit 7541680

Please sign in to comment.