feat(frontend): enhance chat scroll handling for improved user experience
- Implement logic to accurately detect user scroll direction, preventing false positives during content loading. - Update scroll handling in both `useEmbedChatSession` and chat view to maintain auto-follow functionality during streaming. - Introduce a mechanism to differentiate between actual upward scrolls and content growth, enhancing chat usability.
This commit is contained in:
@@ -152,8 +152,22 @@ export function useEmbedChatSession(options: {
|
|||||||
|
|
||||||
const debouncedScrollTop = debounce(onChatScrollTop, 500)
|
const debouncedScrollTop = debounce(onChatScrollTop, 500)
|
||||||
|
|
||||||
|
let lastScrollTop = 0
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
userHasScrolledUp.value = !isNearBottom()
|
const el = scrollContainer.value
|
||||||
|
if (el) {
|
||||||
|
const currentTop = el.scrollTop
|
||||||
|
// Only an actual upward scroll detaches from the live edge. Content that
|
||||||
|
// grows after a chunk (images, diagrams) keeps scrollTop fixed and would
|
||||||
|
// otherwise fire a stale scroll event that falsely marks the user as
|
||||||
|
// scrolled up, killing the auto-follow during streaming.
|
||||||
|
if (currentTop < lastScrollTop - 1) {
|
||||||
|
userHasScrolledUp.value = !isNearBottom()
|
||||||
|
} else if (isNearBottom()) {
|
||||||
|
userHasScrolledUp.value = false
|
||||||
|
}
|
||||||
|
lastScrollTop = currentTop
|
||||||
|
}
|
||||||
debouncedScrollTop()
|
debouncedScrollTop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -421,8 +421,22 @@ const onChatScrollTop = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const debouncedScrollTop = debounce(onChatScrollTop, 500);
|
const debouncedScrollTop = debounce(onChatScrollTop, 500);
|
||||||
|
let lastScrollTop = 0;
|
||||||
const handleScroll = () => {
|
const handleScroll = () => {
|
||||||
userHasScrolledUp.value = !isNearBottom();
|
const el = scrollContainer.value;
|
||||||
|
if (el) {
|
||||||
|
const currentTop = el.scrollTop;
|
||||||
|
// Only an actual upward scroll detaches from the live edge. Content that
|
||||||
|
// grows after a chunk (images, diagrams) keeps scrollTop fixed and would
|
||||||
|
// otherwise fire a stale scroll event that falsely marks the user as
|
||||||
|
// scrolled up, killing the auto-follow during streaming.
|
||||||
|
if (currentTop < lastScrollTop - 1) {
|
||||||
|
userHasScrolledUp.value = !isNearBottom();
|
||||||
|
} else if (isNearBottom()) {
|
||||||
|
userHasScrolledUp.value = false;
|
||||||
|
}
|
||||||
|
lastScrollTop = currentTop;
|
||||||
|
}
|
||||||
debouncedScrollTop();
|
debouncedScrollTop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user