Skip to content

Commit b417245

Browse files
committed
fix(tui): reopen autocomplete after backspace deletes space
1 parent f4cd708 commit b417245

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,30 @@ export function Autocomplete(props: {
457457
hide()
458458
return
459459
}
460+
} else {
461+
// Check if autocomplete should reopen (e.g., after backspace deleted a space)
462+
const cursorOffset = props.input().cursorOffset
463+
if (cursorOffset > 0) {
464+
// Check for "/" at position 0 - reopen slash commands
465+
if (value.startsWith("/") && !value.slice(0, cursorOffset).match(/\s/)) {
466+
show("/")
467+
setStore("index", 0)
468+
return
469+
}
470+
// Check for "@" trigger - find the nearest "@" before cursor with no whitespace between
471+
const textBeforeCursor = value.slice(0, cursorOffset)
472+
const lastAtIndex = textBeforeCursor.lastIndexOf("@")
473+
if (lastAtIndex !== -1) {
474+
const textBetween = textBeforeCursor.slice(lastAtIndex)
475+
const charBeforeAt = lastAtIndex === 0 ? undefined : value[lastAtIndex - 1]
476+
const canTrigger = charBeforeAt === undefined || /\s/.test(charBeforeAt)
477+
if (canTrigger && !textBetween.match(/\s/)) {
478+
show("@")
479+
setStore("index", lastAtIndex)
480+
return
481+
}
482+
}
483+
}
460484
}
461485
},
462486
onKeyDown(e: KeyEvent) {

0 commit comments

Comments
 (0)