adjust auto-scrolling and focus behavior
This commit is contained in:
@@ -331,6 +331,14 @@ export default function App() {
|
||||
const initialRouteSelectionRef = useRef<SidebarSelection | null>(readSidebarSelectionFromUrl());
|
||||
const hasSyncedSelectionHistoryRef = useRef(false);
|
||||
|
||||
const focusComposer = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
window.requestAnimationFrame(() => {
|
||||
const textarea = document.getElementById("composer-input") as HTMLTextAreaElement | null;
|
||||
textarea?.focus();
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof document === "undefined") return;
|
||||
const textarea = document.getElementById("composer-input") as HTMLTextAreaElement | null;
|
||||
@@ -522,8 +530,15 @@ export default function App() {
|
||||
|
||||
useEffect(() => {
|
||||
if (draftKind === "search" || selectedItem?.kind === "search") return;
|
||||
transcriptEndRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
|
||||
}, [draftKind, selectedChat?.messages.length, isSending, selectedItem?.kind]);
|
||||
transcriptEndRef.current?.scrollIntoView({ behavior: isSending ? "smooth" : "auto", block: "end" });
|
||||
}, [draftKind, selectedChat?.messages.length, isSending, selectedItem?.kind, selectedKey]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isSending) return;
|
||||
const hasWorkspaceSelection = Boolean(selectedItem) || draftKind !== null;
|
||||
if (!hasWorkspaceSelection) return;
|
||||
focusComposer();
|
||||
}, [draftKind, isSending, selectedKey]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
@@ -994,6 +1009,7 @@ export default function App() {
|
||||
}
|
||||
} finally {
|
||||
setIsSending(false);
|
||||
focusComposer();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1154,7 +1170,7 @@ export default function App() {
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="flex-1 overflow-y-auto px-3 py-6 md:px-10">
|
||||
<div className={cn("flex-1 overflow-y-auto px-3 pt-6 md:px-10", isSearchMode ? "pb-6" : "pb-28 md:pb-40")}>
|
||||
{!isSearchMode ? (
|
||||
<ChatMessagesPanel messages={displayMessages} isLoading={isLoadingSelection} isSending={isSendingActiveChat} />
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user