Fix file tagging in multi line inputs (#3865)

This commit is contained in:
Greg Pstrucha
2025-11-03 20:22:38 -08:00
committed by GitHub
parent d3566d3b1a
commit 68039d4c71

View File

@@ -52,14 +52,14 @@ 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().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.cursorOffset
const 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().cursorOffset
const 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("/")
}
}
},