mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 10:14:22 +01:00
Fix file tagging in multi line inputs (#3865)
This commit is contained in:
@@ -52,14 +52,14 @@ export function Autocomplete(props: {
|
|||||||
// Track props.value to make memo reactive to text changes
|
// 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
|
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
|
return val
|
||||||
})
|
})
|
||||||
|
|
||||||
function insertPart(text: string, part: PromptInfo["parts"][number]) {
|
function insertPart(text: string, part: PromptInfo["parts"][number]) {
|
||||||
const input = props.input()
|
const input = props.input()
|
||||||
const currentCursorOffset = input.visualCursor.offset
|
const currentCursorOffset = input.cursorOffset
|
||||||
|
|
||||||
const charAfterCursor = props.value.at(currentCursorOffset)
|
const charAfterCursor = props.value.at(currentCursorOffset)
|
||||||
const needsSpace = charAfterCursor !== " "
|
const needsSpace = charAfterCursor !== " "
|
||||||
@@ -344,7 +344,7 @@ export function Autocomplete(props: {
|
|||||||
command.keybinds(false)
|
command.keybinds(false)
|
||||||
setStore({
|
setStore({
|
||||||
visible: mode,
|
visible: mode,
|
||||||
index: props.input().visualCursor.offset,
|
index: props.input().cursorOffset,
|
||||||
position: {
|
position: {
|
||||||
x: props.anchor().x,
|
x: props.anchor().x,
|
||||||
y: props.anchor().y,
|
y: props.anchor().y,
|
||||||
@@ -368,8 +368,8 @@ export function Autocomplete(props: {
|
|||||||
get visible() {
|
get visible() {
|
||||||
return store.visible
|
return store.visible
|
||||||
},
|
},
|
||||||
onInput(value: string) {
|
onInput() {
|
||||||
if (store.visible && Bun.stringWidth(value) <= store.index) hide()
|
if (store.visible && props.input().cursorOffset <= store.index) hide()
|
||||||
},
|
},
|
||||||
onKeyDown(e: KeyEvent) {
|
onKeyDown(e: KeyEvent) {
|
||||||
if (store.visible) {
|
if (store.visible) {
|
||||||
@@ -381,23 +381,20 @@ export function Autocomplete(props: {
|
|||||||
}
|
}
|
||||||
if (!store.visible) {
|
if (!store.visible) {
|
||||||
if (e.name === "@") {
|
if (e.name === "@") {
|
||||||
const cursorOffset = props.input().visualCursor.offset
|
const cursorOffset = props.input().cursorOffset
|
||||||
const charBeforeCursor =
|
const charBeforeCursor =
|
||||||
cursorOffset === 0
|
cursorOffset === 0
|
||||||
? undefined
|
? undefined
|
||||||
: props.input().getTextRange(cursorOffset - 1, cursorOffset)
|
: props.input().getTextRange(cursorOffset - 1, cursorOffset)
|
||||||
|
const canTrigger =
|
||||||
if (
|
charBeforeCursor === undefined ||
|
||||||
charBeforeCursor === " " ||
|
charBeforeCursor === "" ||
|
||||||
charBeforeCursor === "\n" ||
|
/\s/.test(charBeforeCursor)
|
||||||
charBeforeCursor === undefined
|
if (canTrigger) show("@")
|
||||||
) {
|
|
||||||
show("@")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.name === "/") {
|
if (e.name === "/") {
|
||||||
if (props.input().visualCursor.offset === 0) show("/")
|
if (props.input().cursorOffset === 0) show("/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user