Skip to content

Commit 54a70ef

Browse files
committed
Favor utf-16 view
1 parent b4e7f19 commit 54a70ef

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,22 @@ extension WindowBaseCommandHandler {
372372
return false
373373
}
374374
let line = editor.lines[selection.start.line]
375-
guard selection.start.character > 0, selection.start.character < line.count else {
376-
return false
377-
}
378-
let substring =
379-
line[line.startIndex..<line
380-
.index(line.startIndex, offsetBy: selection.start.character)]
375+
guard selection.start.character > 0,
376+
selection.start.character < line.utf16.count
377+
else { return false }
378+
let substring = String(
379+
line.utf16[line.utf16.startIndex..<(line.index(
380+
line.utf16.startIndex,
381+
offsetBy: selection.start.character,
382+
limitedBy: line.utf16.endIndex
383+
) ?? line.utf16.endIndex)]
384+
) ?? String(
385+
line[line.startIndex..<(line.index(
386+
line.startIndex,
387+
offsetBy: selection.start.character,
388+
limitedBy: line.endIndex
389+
) ?? line.endIndex)]
390+
)
381391
return substring.allSatisfy { $0.isWhitespace }
382392
}()
383393

@@ -398,13 +408,13 @@ extension WindowBaseCommandHandler {
398408
let viewStore = Service.shared.guiController.viewStore
399409

400410
let customCommandTemplateProcessor = CustomCommandTemplateProcessor()
401-
411+
402412
let newExtraSystemPrompt: String? = if let extraSystemPrompt {
403413
await customCommandTemplateProcessor.process(extraSystemPrompt)
404414
} else {
405415
nil
406416
}
407-
417+
408418
let newPrompt: String? = if let prompt {
409419
await customCommandTemplateProcessor.process(prompt)
410420
} else {

0 commit comments

Comments
 (0)