Skip to content

Commit e52fe95

Browse files
fix: allow spaces in file paths during @ tab-completion (anomalyco#19152)
When tab-completing through directories with spaces (e.g. 'Car Kit/'), the autocomplete would close because the whitespace check treated spaces as end-of-reference markers. Added a 'browsing' flag that activates when expandDirectory() is called. While browsing, only newlines/tabs close the autocomplete — spaces are allowed. Normal typing behavior is unchanged.
1 parent 652313e commit e52fe95

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function Autocomplete(props: {
8787
selected: 0,
8888
visible: false as AutocompleteRef["visible"],
8989
input: "keyboard" as "keyboard" | "mouse",
90+
browsing: false,
9091
})
9192

9293
const [positionTick, setPositionTick] = createSignal(0)
@@ -470,6 +471,7 @@ export function Autocomplete(props: {
470471
const endCursor = input.logicalCursor
471472

472473
input.deleteRange(startCursor.row, startCursor.col, endCursor.row, endCursor.col)
474+
setStore("browsing", true)
473475
input.insertText("@" + path)
474476

475477
setStore("selected", 0)
@@ -495,6 +497,7 @@ export function Autocomplete(props: {
495497
}
496498
command.keybinds(true)
497499
setStore("visible", false)
500+
setStore("browsing", false)
498501
}
499502

500503
onMount(() => {
@@ -508,7 +511,8 @@ export function Autocomplete(props: {
508511
// Typed text before the trigger
509512
props.input().cursorOffset <= store.index ||
510513
// There is a space between the trigger and the cursor
511-
props.input().getTextRange(store.index, props.input().cursorOffset).match(/\s/) ||
514+
// When browsing directories via tab-complete, allow spaces in file paths
515+
props.input().getTextRange(store.index, props.input().cursorOffset).match(store.browsing ? /[\n\r\t]/ : /\s/) ||
512516
// "/<command>" is not the sole content
513517
(store.visible === "/" && value.match(/^\S+\s+\S+\s*$/))
514518
) {

0 commit comments

Comments
 (0)