enable @filename parts within text, not just at end
Some checks are pending
format / format (push) Waiting to run
snapshot / publish (push) Waiting to run
test / test (push) Waiting to run

This commit is contained in:
Sebastian Herrlinger 2025-10-29 14:03:03 +01:00
parent 342b747461
commit f1f51b483b

View file

@ -51,10 +51,13 @@ export function Autocomplete(props: {
})
function insertPart(text: string, part: PromptInfo["parts"][number]) {
const append = "@" + text + " "
const input = props.input()
const currentCursorOffset = input.visualCursor.offset
const charAfterCursor = props.value.at(currentCursorOffset)
const needsSpace = charAfterCursor !== " " && charAfterCursor !== undefined
const append = "@" + text + (needsSpace ? " " : "")
input.cursorOffset = store.index
const startCursor = input.logicalCursor
input.cursorOffset = currentCursorOffset
@ -316,8 +319,9 @@ export function Autocomplete(props: {
}
if (!store.visible) {
if (e.name === "@") {
const last = props.value.at(-1)
if (last === " " || last === undefined) {
const cursorOffset = props.input().visualCursor.offset
const charBeforeCursor = cursorOffset === 0 ? undefined : props.value.at(cursorOffset - 1)
if (charBeforeCursor === " " || charBeforeCursor === undefined) {
show("@")
}
}