切换会话时,会话输入框自动获得焦点

This commit is contained in:
xintaofei
2026-03-10 23:54:30 +08:00
parent 5960ccebb9
commit 16a3267e69
4 changed files with 20 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ interface ChatInputProps {
availableCommands?: AvailableCommandInfo[] | null availableCommands?: AvailableCommandInfo[] | null
attachmentTabId?: string | null attachmentTabId?: string | null
draftStorageKey?: string | null draftStorageKey?: string | null
isActive?: boolean
} }
export function ChatInput({ export function ChatInput({
@@ -47,6 +48,7 @@ export function ChatInput({
availableCommands, availableCommands,
attachmentTabId, attachmentTabId,
draftStorageKey, draftStorageKey,
isActive,
}: ChatInputProps) { }: ChatInputProps) {
const t = useTranslations("Folder.chat.chatInput") const t = useTranslations("Folder.chat.chatInput")
const isConnected = status === "connected" const isConnected = status === "connected"
@@ -73,6 +75,7 @@ export function ChatInput({
availableCommands={availableCommands} availableCommands={availableCommands}
attachmentTabId={attachmentTabId} attachmentTabId={attachmentTabId}
draftStorageKey={draftStorageKey} draftStorageKey={draftStorageKey}
isActive={isActive}
placeholder={ placeholder={
isConnecting isConnecting
? t("connecting") ? t("connecting")

View File

@@ -33,6 +33,7 @@ interface ConversationShellProps {
attachmentTabId?: string | null attachmentTabId?: string | null
draftStorageKey?: string | null draftStorageKey?: string | null
hideInput?: boolean hideInput?: boolean
isActive?: boolean
} }
export function ConversationShell({ export function ConversationShell({
@@ -57,6 +58,7 @@ export function ConversationShell({
attachmentTabId, attachmentTabId,
draftStorageKey, draftStorageKey,
hideInput = false, hideInput = false,
isActive,
}: ConversationShellProps) { }: ConversationShellProps) {
return ( return (
<div className="flex h-full min-h-0 flex-col"> <div className="flex h-full min-h-0 flex-col">
@@ -85,6 +87,7 @@ export function ConversationShell({
availableCommands={availableCommands} availableCommands={availableCommands}
attachmentTabId={attachmentTabId} attachmentTabId={attachmentTabId}
draftStorageKey={draftStorageKey} draftStorageKey={draftStorageKey}
isActive={isActive}
/> />
)} )}

View File

@@ -54,6 +54,7 @@ interface MessageInputProps {
promptCapabilities: PromptCapabilitiesInfo promptCapabilities: PromptCapabilitiesInfo
attachmentTabId?: string | null attachmentTabId?: string | null
draftStorageKey?: string | null draftStorageKey?: string | null
isActive?: boolean
} }
interface ResourceInputAttachment { interface ResourceInputAttachment {
@@ -252,6 +253,7 @@ export function MessageInput({
promptCapabilities, promptCapabilities,
attachmentTabId, attachmentTabId,
draftStorageKey, draftStorageKey,
isActive = false,
}: MessageInputProps) { }: MessageInputProps) {
const t = useTranslations("Folder.chat.messageInput") const t = useTranslations("Folder.chat.messageInput")
const effectiveDraftStorageKey = draftStorageKey ?? attachmentTabId ?? null const effectiveDraftStorageKey = draftStorageKey ?? attachmentTabId ?? null
@@ -263,11 +265,20 @@ export function MessageInput({
const [attachments, setAttachments] = useState<InputAttachment[]>([]) const [attachments, setAttachments] = useState<InputAttachment[]>([])
const [isDragActive, setIsDragActive] = useState(false) const [isDragActive, setIsDragActive] = useState(false)
const containerRef = useRef<HTMLDivElement>(null) const containerRef = useRef<HTMLDivElement>(null)
const textareaRef = useRef<HTMLTextAreaElement>(null)
const lastDomDropAtRef = useRef(0) const lastDomDropAtRef = useRef(0)
const composingRef = useRef(false) const composingRef = useRef(false)
const textRef = useRef(text) const textRef = useRef(text)
const disabledRef = useRef(disabled) const disabledRef = useRef(disabled)
const isPromptingRef = useRef(isPrompting) const isPromptingRef = useRef(isPrompting)
useEffect(() => {
if (isActive && !disabled && !isPrompting) {
requestAnimationFrame(() => {
textareaRef.current?.focus()
})
}
}, [isActive, disabled, isPrompting])
const dragActiveRef = useRef(false) const dragActiveRef = useRef(false)
const canAttachImages = promptCapabilities.image const canAttachImages = promptCapabilities.image
@@ -1001,6 +1012,7 @@ export function MessageInput({
/> />
)} )}
<Textarea <Textarea
ref={textareaRef}
value={text} value={text}
onChange={handleTextChange} onChange={handleTextChange}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}

View File

@@ -575,6 +575,7 @@ const ConversationTabView = memo(function ConversationTabView({
attachmentTabId={tabId} attachmentTabId={tabId}
draftStorageKey={draftStorageKey} draftStorageKey={draftStorageKey}
hideInput={isWelcomeMode} hideInput={isWelcomeMode}
isActive={isActive}
> >
{isWelcomeMode ? ( {isWelcomeMode ? (
<div className="flex h-full min-h-0 flex-col items-center justify-center"> <div className="flex h-full min-h-0 flex-col items-center justify-center">
@@ -623,6 +624,7 @@ const ConversationTabView = memo(function ConversationTabView({
availableCommands={connectionCommands} availableCommands={connectionCommands}
attachmentTabId={tabId} attachmentTabId={tabId}
draftStorageKey={draftStorageKey} draftStorageKey={draftStorageKey}
isActive={isActive}
/> />
</div> </div>
</div> </div>