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:
wizardchen
2026-06-18 16:53:10 +08:00
committed by lyingbug
parent 80bcf200b6
commit c6b5d2e77b
2 changed files with 30 additions and 2 deletions
@@ -152,8 +152,22 @@ export function useEmbedChatSession(options: {
const debouncedScrollTop = debounce(onChatScrollTop, 500)
let lastScrollTop = 0
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()
}
+15 -1
View File
@@ -421,8 +421,22 @@ const onChatScrollTop = () => {
}
}
const debouncedScrollTop = debounce(onChatScrollTop, 500);
let lastScrollTop = 0;
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();
};