diff --git a/src/components/file-picker.tsx b/src/components/file-picker.tsx index b450b980..67f66f2f 100644 --- a/src/components/file-picker.tsx +++ b/src/components/file-picker.tsx @@ -174,6 +174,14 @@ const FilePicker: Component = (props) => { const listener = (e: KeyboardEvent) => { if (!props.open) return const fileList = files() + + if (e.key === "Escape") { + e.preventDefault() + e.stopPropagation() + props.onClose() + return + } + if (fileList.length === 0) return if (e.key === "ArrowDown") { @@ -189,14 +197,11 @@ const FilePicker: Component = (props) => { if (fileList[selectedIndex()]) { handleSelect(fileList[selectedIndex()].path) } - } else if (e.key === "Escape") { - e.preventDefault() - props.onClose() } } - document.addEventListener("keydown", listener) - onCleanup(() => document.removeEventListener("keydown", listener)) + document.addEventListener("keydown", listener, true) + onCleanup(() => document.removeEventListener("keydown", listener, true)) }) return ( diff --git a/src/components/prompt-input.tsx b/src/components/prompt-input.tsx index c5d7e540..5f09bc88 100644 --- a/src/components/prompt-input.tsx +++ b/src/components/prompt-input.tsx @@ -34,6 +34,7 @@ export default function PromptInput(props: PromptInputProps) { const [fileSearchQuery, setFileSearchQuery] = createSignal("") const [atPosition, setAtPosition] = createSignal(null) const [isDragging, setIsDragging] = createSignal(false) + const [ignoredAtPositions, setIgnoredAtPositions] = createSignal>(new Set()) let textareaRef: HTMLTextAreaElement | undefined let containerRef: HTMLDivElement | undefined @@ -103,6 +104,7 @@ export default function PromptInput(props: PromptInputProps) { await props.onSend(text, currentAttachments) setPrompt("") clearAttachments(props.instanceId, props.sessionId) + setIgnoredAtPositions(new Set()) if (textareaRef) { textareaRef.style.height = "auto" @@ -129,7 +131,7 @@ export default function PromptInput(props: PromptInputProps) { const textBeforeCursor = value.substring(0, cursorPos) const lastAtIndex = textBeforeCursor.lastIndexOf("@") - if (lastAtIndex !== -1) { + if (lastAtIndex !== -1 && !ignoredAtPositions().has(lastAtIndex)) { const textAfterAt = value.substring(lastAtIndex + 1, cursorPos) const hasSpace = textAfterAt.includes(" ") || textAfterAt.includes("\n") @@ -176,10 +178,14 @@ export default function PromptInput(props: PromptInputProps) { } function handleFilePickerClose() { + const pos = atPosition() + if (pos !== null) { + setIgnoredAtPositions((prev) => new Set(prev).add(pos)) + } setShowFilePicker(false) setAtPosition(null) setFileSearchQuery("") - textareaRef?.focus() + setTimeout(() => textareaRef?.focus(), 0) } function handleFilePickerNavigate(_direction: "up" | "down") {} @@ -227,13 +233,6 @@ export default function PromptInput(props: PromptInputProps) { return (
- 0}> -
- - {(att) => handleRemoveAttachment(att.id)} />} - -
-
+ 0}> +
+ + {(att) => handleRemoveAttachment(att.id)} />} + +
+
+