The open source coding agent.
TypeScript
fix: Autocomplete with existing space after trigger (#4121)
Haris Gušićb1b73c9deb3d
diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsxindex b9b27bb1e7e..3029eafcce3 100644--- a/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx+++ b/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx@@ -53,15 +53,7 @@ export function Autocomplete(props: {// Track props.value to make memo reactive to text changesprops.value // <- there surely is a better way to do this, like making .input() reactive- const val = props.input().getTextRange(store.index + 1, props.input().cursorOffset + 1)-- // If the filter contains a space, hide the autocomplete- if (val.includes(" ")) {- hide()- return undefined- }-- return val+ return props.input().getTextRange(store.index + 1, props.input().cursorOffset)})function insertPart(text: string, part: PromptInfo["parts"][number]) {@@ -387,17 +379,19 @@ export function Autocomplete(props: {get visible() {return store.visible},- onInput() {+ onInput(value) {if (store.visible) {- if (props.input().cursorOffset <= store.index) {+ if (+ // Typed text before the trigger+ props.input().cursorOffset <= store.index ||+ // There is a space between the trigger and the cursor+ props.input().getTextRange(store.index, props.input().cursorOffset).match(/\s/) ||+ // "/<command>" is not the sole content+ (store.visible === "/" && value.match(/^\S+\s+\S+\s*$/))+ ) {hide()return}- // Check if a space was typed after the trigger character- const currentText = props.input().getTextRange(store.index + 1, props.input().cursorOffset + 1)- if (currentText.includes(" ")) {- hide()- }}},onKeyDown(e: KeyEvent) {