Skip to content

Commit f1f51b4

Browse files
committed
enable @filename parts within text, not just at end
1 parent 342b747 commit f1f51b4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@ export function Autocomplete(props: {
5151
})
5252

5353
function insertPart(text: string, part: PromptInfo["parts"][number]) {
54-
const append = "@" + text + " "
5554
const input = props.input()
5655
const currentCursorOffset = input.visualCursor.offset
5756

57+
const charAfterCursor = props.value.at(currentCursorOffset)
58+
const needsSpace = charAfterCursor !== " " && charAfterCursor !== undefined
59+
const append = "@" + text + (needsSpace ? " " : "")
60+
5861
input.cursorOffset = store.index
5962
const startCursor = input.logicalCursor
6063
input.cursorOffset = currentCursorOffset
@@ -316,8 +319,9 @@ export function Autocomplete(props: {
316319
}
317320
if (!store.visible) {
318321
if (e.name === "@") {
319-
const last = props.value.at(-1)
320-
if (last === " " || last === undefined) {
322+
const cursorOffset = props.input().visualCursor.offset
323+
const charBeforeCursor = cursorOffset === 0 ? undefined : props.value.at(cursorOffset - 1)
324+
if (charBeforeCursor === " " || charBeforeCursor === undefined) {
321325
show("@")
322326
}
323327
}

0 commit comments

Comments
 (0)