Merge pull request #2848 from continuedev/dallin/scroll-chat-to-bottom

Scroll chat to bottom on session change and load
This commit is contained in:
Nate Sesti 2024-11-08 14:40:28 -08:00 • committed by GitHub
commit b9b71eba7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -136,7 +136,6 @@ export function Chat() {
const { streamResponse } = useChatHandler(dispatch, ideMessenger);
const onboardingCard = useOnboardingCard();
const { showTutorialCard, closeTutorialCard } = useTutorialCard();
const sessionState = useSelector((state: RootState) => state.state);
const defaultModel = useSelector(defaultModelSelector);
const ttsActive = useSelector((state: RootState) => state.state.ttsActive);
const active = useSelector((state: RootState) => state.state.active);
@ -148,7 +147,7 @@ export function Chat() {
const { saveSession, getLastSessionId, loadLastSession } =
useHistory(dispatch);
const scrollToBottom = useCallback(() => {
const snapToBottom = useCallback(() => {
if (!topGuiDivRef.current) return;
const elem = topGuiDivRef.current;
elem.scrollTop = elem.scrollHeight - elem.clientHeight;
@ -156,9 +155,26 @@ export function Chat() {
setIsAtBottom(true);
}, [topGuiDivRef, setIsAtBottom]);
const smoothScrollToBottom = useCallback(async () => {
if (!topGuiDivRef.current) return;
const elem = topGuiDivRef.current
elem.scrollTo({
top: elem.scrollHeight - elem.clientHeight,
behavior: 'smooth'
})
setIsAtBottom(true);
}, [topGuiDivRef, setIsAtBottom]);
useEffect(() => {
if (active) scrollToBottom();
}, [active, scrollToBottom]);
if (active) snapToBottom();
}, [active, snapToBottom]);
useEffect(() => {
setTimeout(() => {
smoothScrollToBottom();
}, 250)
}, [smoothScrollToBottom, state.sessionId]);
useEffect(() => {
// Cmd + Backspace to delete current step
@ -284,8 +300,8 @@ export function Chat() {
}
},
[
sessionState.history,
sessionState.contextItems,
state.history,
state.contextItems,
defaultModel,
state,
streamResponse,
@ -370,11 +386,11 @@ export function Chat() {
: true
: stepsOpen[index]!
}
onToggle={() => {}}
onToggle={() => { }}
>
<StepContainer
index={index}
isLast={index === sessionState.history.length - 1}
isLast={index === state.history.length - 1}
isFirst={index === 0}
open={
typeof stepsOpen[index] === "undefined"
@ -382,14 +398,14 @@ export function Chat() {
: stepsOpen[index]!
}
key={index}
onUserInput={(input: string) => {}}
onUserInput={(input: string) => { }}
item={item}
onReverse={() => {}}
onReverse={() => { }}
onRetry={() => {
streamResponse(
state.history[index - 1].editorState,
state.history[index - 1].modifiers ??
defaultInputModifiers,
defaultInputModifiers,
ideMessenger,
index - 1,
);