Skip to content

Commit 6deaf54

Browse files
committed
use new opentui getTextRange method and Bun.stringWidth instead of value.length to mitigate issues like #3734
1 parent d549cd3 commit 6deaf54

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

‎bun.lock‎

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/opencode/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"@opencode-ai/plugin": "workspace:*",
5555
"@opencode-ai/script": "workspace:*",
5656
"@opencode-ai/sdk": "workspace:*",
57-
"@opentui/core": "0.1.32",
58-
"@opentui/solid": "0.1.32",
57+
"@opentui/core": "0.1.33",
58+
"@opentui/solid": "0.1.33",
5959
"@parcel/watcher": "2.5.1",
6060
"@solid-primitives/event-bus": "1.1.2",
6161
"@pierre/precision-diffs": "catalog:",

‎packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ export function Autocomplete(props: {
4949
})
5050
const filter = createMemo(() => {
5151
if (!store.visible) return
52-
return props.value.substring(store.index + 1).split(" ")[0]
52+
// Track props.value to make memo reactive to text changes
53+
props.value // <- there surely is a better way to do this, like making .input() reactive
54+
55+
const val = props.input().getTextRange(store.index + 1, props.input().visualCursor.offset + 1)
56+
57+
return val
5358
})
5459

5560
function insertPart(text: string, part: PromptInfo["parts"][number]) {
@@ -70,7 +75,7 @@ export function Autocomplete(props: {
7075

7176
const virtualText = "@" + text
7277
const extmarkStart = store.index
73-
const extmarkEnd = extmarkStart + virtualText.length
78+
const extmarkEnd = extmarkStart + Bun.stringWidth(virtualText)
7479

7580
const styleId =
7681
part.type === "file"
@@ -364,7 +369,7 @@ export function Autocomplete(props: {
364369
return store.visible
365370
},
366371
onInput(value: string) {
367-
if (store.visible && value.length <= store.index) hide()
372+
if (store.visible && Bun.stringWidth(value) <= store.index) hide()
368373
},
369374
onKeyDown(e: KeyEvent) {
370375
if (store.visible) {
@@ -378,7 +383,10 @@ export function Autocomplete(props: {
378383
if (e.name === "@") {
379384
const cursorOffset = props.input().visualCursor.offset
380385
const charBeforeCursor =
381-
cursorOffset === 0 ? undefined : props.value.at(cursorOffset - 1)
386+
cursorOffset === 0
387+
? undefined
388+
: props.input().getTextRange(cursorOffset - 1, cursorOffset)
389+
382390
if (
383391
charBeforeCursor === " " ||
384392
charBeforeCursor === "\n" ||

0 commit comments

Comments
 (0)