From e2567c4d1c0d2b14dd6ebc33c2899ee02ae4ca2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E6=9E=B3?= <7854742+wang_rumeng@user.noreply.gitee.com> Date: Tue, 26 Aug 2025 16:45:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96chatbox=E5=85=89=E6=A0=87?= =?UTF-8?q?=E8=81=9A=E7=84=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SmartChatBox/InputBar.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/components/SmartChatBox/InputBar.tsx b/components/SmartChatBox/InputBar.tsx index cf8b1b5..3e8fc12 100644 --- a/components/SmartChatBox/InputBar.tsx +++ b/components/SmartChatBox/InputBar.tsx @@ -91,6 +91,22 @@ export function InputBar({ onSend, setVideoPreview, initialVideoUrl, initialVide debouncedAdjustHeight(); }, [text, debouncedAdjustHeight]); + // 布局切换时保持输入框焦点并将光标移到末尾 + useEffect(() => { + // 等待布局动画完成后再聚焦,避免动画过程中的视觉跳动 + const focusTimeout = setTimeout(() => { + const textarea = textareaRef.current; + if (textarea) { + textarea.focus(); + // 将光标移动到文本末尾 + const length = textarea.value.length; + textarea.setSelectionRange(length, length); + } + }, 200); // 与布局动画时长保持一致 + + return () => clearTimeout(focusTimeout); + }, [isMultiline]); + const handleSend = () => { const blocks: MessageBlock[] = []; if (text.trim()) blocks.push({ type: "text" as const, text: text.trim() }); @@ -247,11 +263,11 @@ export function InputBar({ onSend, setVideoPreview, initialVideoUrl, initialVide )} {/* 文本输入 */} - +