The open source coding agent.
TypeScript
Fix file tagging in multi line inputs (#3865)
Greg Pstrucha68039d4c7193
diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsxindex 173287194b7..c2d6a4db1c7 100644--- a/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx+++ b/packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx@@ -52,14 +52,14 @@ 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().visualCursor.offset + 1)+ const val = props.input().getTextRange(store.index + 1, props.input().cursorOffset + 1)return val})function insertPart(text: string, part: PromptInfo["parts"][number]) {const input = props.input()- const currentCursorOffset = input.visualCursor.offset+ const currentCursorOffset = input.cursorOffsetconst charAfterCursor = props.value.at(currentCursorOffset)const needsSpace = charAfterCursor !== " "@@ -344,7 +344,7 @@ export function Autocomplete(props: {command.keybinds(false)setStore({visible: mode,- index: props.input().visualCursor.offset,+ index: props.input().cursorOffset,position: {x: props.anchor().x,y: props.anchor().y,@@ -368,8 +368,8 @@ export function Autocomplete(props: {get visible() {return store.visible},- onInput(value: string) {- if (store.visible && Bun.stringWidth(value) <= store.index) hide()+ onInput() {+ if (store.visible && props.input().cursorOffset <= store.index) hide()},onKeyDown(e: KeyEvent) {if (store.visible) {@@ -381,23 +381,20 @@ export function Autocomplete(props: {}if (!store.visible) {if (e.name === "@") {- const cursorOffset = props.input().visualCursor.offset+ const cursorOffset = props.input().cursorOffsetconst charBeforeCursor =cursorOffset === 0? undefined: props.input().getTextRange(cursorOffset - 1, cursorOffset)-- if (- charBeforeCursor === " " ||- charBeforeCursor === "\n" ||- charBeforeCursor === undefined- ) {- show("@")- }+ const canTrigger =+ charBeforeCursor === undefined ||+ charBeforeCursor === "" ||+ /\s/.test(charBeforeCursor)+ if (canTrigger) show("@")}if (e.name === "/") {- if (props.input().visualCursor.offset === 0) show("/")+ if (props.input().cursorOffset === 0) show("/")}}},