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 initialRouteSelectionRef = useRef<SidebarSelection | null>(readSidebarSelectionFromUrl());
|
||||||
const hasSyncedSelectionHistoryRef = useRef(false);
|
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(() => {
|
useEffect(() => {
|
||||||
if (typeof document === "undefined") return;
|
if (typeof document === "undefined") return;
|
||||||
const textarea = document.getElementById("composer-input") as HTMLTextAreaElement | null;
|
const textarea = document.getElementById("composer-input") as HTMLTextAreaElement | null;
|
||||||
@@ -522,8 +530,15 @@ export default function App() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (draftKind === "search" || selectedItem?.kind === "search") return;
|
if (draftKind === "search" || selectedItem?.kind === "search") return;
|
||||||
transcriptEndRef.current?.scrollIntoView({ behavior: "smooth", block: "end" });
|
transcriptEndRef.current?.scrollIntoView({ behavior: isSending ? "smooth" : "auto", block: "end" });
|
||||||
}, [draftKind, selectedChat?.messages.length, isSending, selectedItem?.kind]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
@@ -994,6 +1009,7 @@ export default function App() {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsSending(false);
|
setIsSending(false);
|
||||||
|
focusComposer();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1154,7 +1170,7 @@ export default function App() {
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</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 ? (
|
{!isSearchMode ? (
|
||||||
<ChatMessagesPanel messages={displayMessages} isLoading={isLoadingSelection} isSending={isSendingActiveChat} />
|
<ChatMessagesPanel messages={displayMessages} isLoading={isLoadingSelection} isSending={isSendingActiveChat} />
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
Reference in New Issue
Block a user