From a7f2c0aff51c08ac9a0f0e0807e11d14d9844abc Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sat, 18 Oct 2025 22:31:46 +0000 Subject: [PATCH] fix(chat): focus edit textarea before scrolling to ensure edit mode input mounts and scrolls into view --- webview-ui/src/components/chat/ChatRow.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index 112a2be809..2a58ec2c81 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -137,6 +137,7 @@ export const ChatRowContent = ({ const [editMode, setEditMode] = useState(mode || "code") const [editImages, setEditImages] = useState([]) const editAreaRef = useRef(null) + const editTextAreaRef = useRef(null) // Handle message events for image selection during edit mode useEffect(() => { @@ -166,14 +167,25 @@ export const ChatRowContent = ({ // No need to notify the backend }, [message.text, message.images, mode]) - // Scroll to edit area when entering edit mode + // Scroll and focus edit textarea when entering edit mode useEffect(() => { if (!isEditing) return let cancelled = false const timeoutId = window.setTimeout(() => { if (cancelled) return - editAreaRef.current?.scrollIntoView({ + const targetEl = editTextAreaRef.current ?? editAreaRef.current + + // Focus first to ensure caret is visible; preventScroll avoids double-jump + if (editTextAreaRef.current) { + try { + ;(editTextAreaRef.current as any).focus({ preventScroll: true }) + } catch { + editTextAreaRef.current.focus() + } + } + + targetEl?.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest", @@ -1141,6 +1153,7 @@ export const ChatRowContent = ({ {isEditing ? (