diff --git a/packages/app/src/components/prompt-input.tsx b/packages/app/src/components/prompt-input.tsx index 1a25d10f78..6b5fd8844f 100644 --- a/packages/app/src/components/prompt-input.tsx +++ b/packages/app/src/components/prompt-input.tsx @@ -214,6 +214,7 @@ export const PromptInput: Component = (props) => { let fileInputRef: HTMLInputElement | undefined let scrollRef!: HTMLDivElement let slashPopoverRef!: HTMLDivElement + let restoreEndOnFocus = true const mirror = { input: false } const inset = 56 @@ -593,6 +594,16 @@ export const PromptInput: Component = (props) => { }) } + const handleFocus = () => { + if (!restoreEndOnFocus) return + restoreEndOnFocus = false + requestAnimationFrame(() => { + if (document.activeElement !== editorRef) return + setCursorPosition(editorRef, prompt.cursor() ?? promptLength(prompt.current())) + queueScroll() + }) + } + const renderEditorWithCursor = (parts: Prompt) => { const cursor = currentCursor() renderEditor(parts) @@ -1380,6 +1391,11 @@ export const PromptInput: Component = (props) => { })) const newSession = () => props.variant === "new-session" + const bindEditorRef = (el: HTMLDivElement) => { + editorRef = el + restoreEndOnFocus = true + props.ref?.(el) + } const showAgentControl = createMemo(() => props.controls.agents.visible && props.controls.agents.options.length > 0) const agentControlState = createMemo(() => ({ title: language.t("command.agent.cycle"), @@ -1463,10 +1479,7 @@ export const PromptInput: Component = (props) => {
(scrollRef = el)}>
{ - editorRef = el - props.ref?.(el) - }} + ref={bindEditorRef} role="textbox" aria-multiline="true" aria-label={designPlaceholder()} @@ -1481,6 +1494,7 @@ export const PromptInput: Component = (props) => { onPaste={handlePaste} onCompositionStart={handleCompositionStart} onCompositionEnd={handleCompositionEnd} + onFocus={handleFocus} onBlur={handleBlur} onKeyDown={handleKeyDown} classList={{ @@ -1501,7 +1515,7 @@ export const PromptInput: Component = (props) => {
-
+
{fileAttachmentInput()} = (props) => { >
{ - editorRef = el - props.ref?.(el) - }} + ref={bindEditorRef} role="textbox" aria-multiline="true" aria-label={placeholder()} @@ -1662,6 +1673,7 @@ export const PromptInput: Component = (props) => { onPaste={handlePaste} onCompositionStart={handleCompositionStart} onCompositionEnd={handleCompositionEnd} + onFocus={handleFocus} onBlur={handleBlur} onKeyDown={handleKeyDown} classList={{