summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHaris Gušić <[email protected]>2025-11-20 17:37:45 +0100
committerGitHub <[email protected]>2025-11-20 10:37:45 -0600
commitb1b73c9deb3db96620640c49b0215f97a58987e7 (patch)
treee2e1a8ff20fd91be0d02a3d4d047a91647e4eb08
parent774377330b1dd3e1586ddd596698589bf973eaf0 (diff)
downloadopencode-b1b73c9deb3db96620640c49b0215f97a58987e7.tar.gz
opencode-b1b73c9deb3db96620640c49b0215f97a58987e7.zip
fix: Autocomplete with existing space after trigger (#4121)
Co-authored-by: GitHub Action <[email protected]>
-rw-r--r--packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx26
1 files changed, 10 insertions, 16 deletions
diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx
index b9b27bb1e..3029eafcc 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 changes
props.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) {