summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuorui Yu <[email protected]>2026-01-06 03:08:17 +0800
committerGitHub <[email protected]>2026-01-05 13:08:17 -0600
commit5a38a6f248555e03d91b35c446ea0f9f4753b325 (patch)
treec655e0a820c8717870a758ddc537cac2caf37a29
parentaef01003e7d73ecd411339628eabfc84b010efb5 (diff)
downloadopencode-5a38a6f248555e03d91b35c446ea0f9f4753b325.tar.gz
opencode-5a38a6f248555e03d91b35c446ea0f9f4753b325.zip
tui: autocomplete: expand directory on Tab, select on Enter (#6975)
Signed-off-by: yuguorui <[email protected]>
-rw-r--r--packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx36
1 files changed, 35 insertions, 1 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 f5116f037..ae4f18d4c 100644
--- a/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx
+++ b/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx
@@ -55,6 +55,7 @@ export type AutocompleteOption = {
aliases?: string[]
disabled?: boolean
description?: string
+ isDirectory?: boolean
onSelect?: () => void
}
@@ -200,8 +201,10 @@ export function Autocomplete(props: {
url = urlObj.toString()
}
+ const isDir = item.endsWith("/")
return {
display: Locale.truncateMiddle(filename, width),
+ isDirectory: isDir,
onSelect: () => {
insertPart(filename, {
type: "file",
@@ -511,6 +514,27 @@ export function Autocomplete(props: {
selected.onSelect?.()
}
+ function expandDirectory() {
+ const selected = options()[store.selected]
+ if (!selected) return
+
+ const input = props.input()
+ const currentCursorOffset = input.cursorOffset
+
+ const displayText = selected.display.trimEnd()
+ const path = displayText.startsWith("@") ? displayText.slice(1) : displayText
+
+ input.cursorOffset = store.index
+ const startCursor = input.logicalCursor
+ input.cursorOffset = currentCursorOffset
+ const endCursor = input.logicalCursor
+
+ input.deleteRange(startCursor.row, startCursor.col, endCursor.row, endCursor.col)
+ input.insertText("@" + path)
+
+ setStore("selected", 0)
+ }
+
function show(mode: "@" | "/") {
command.keybinds(false)
setStore({
@@ -575,11 +599,21 @@ export function Autocomplete(props: {
e.preventDefault()
return
}
- if (name === "return" || name === "tab") {
+ if (name === "return") {
select()
e.preventDefault()
return
}
+ if (name === "tab") {
+ const selected = options()[store.selected]
+ if (selected?.isDirectory) {
+ expandDirectory()
+ } else {
+ select()
+ }
+ e.preventDefault()
+ return
+ }
}
if (!store.visible) {
if (e.name === "@") {