mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2026-03-17 19:04:39 +01:00
UI: Fix an autoscroll race condition during chat streaming
This commit is contained in:
parent
5833d94d7f
commit
fef95b9e56
|
|
@ -145,6 +145,7 @@ targetElement.classList.add("pretty_scrollbar");
|
|||
targetElement.classList.add("chat-parent");
|
||||
window.isScrolled = false;
|
||||
let scrollTimeout;
|
||||
let isProgrammaticScroll = false;
|
||||
|
||||
targetElement.addEventListener("scroll", function() {
|
||||
let diff = targetElement.scrollHeight - targetElement.clientHeight;
|
||||
|
|
@ -157,9 +158,10 @@ targetElement.addEventListener("scroll", function() {
|
|||
|
||||
if(isAtBottomNow) {
|
||||
window.isScrolled = false;
|
||||
} else {
|
||||
} else if (!isProgrammaticScroll) {
|
||||
window.isScrolled = true;
|
||||
}
|
||||
isProgrammaticScroll = false;
|
||||
|
||||
// Clear previous timeout and set new one
|
||||
clearTimeout(scrollTimeout);
|
||||
|
|
@ -193,6 +195,7 @@ const observer = new MutationObserver(function(mutations) {
|
|||
if (!window.isScrolled && !isScrollingClassOnly) {
|
||||
const maxScroll = targetElement.scrollHeight - targetElement.clientHeight;
|
||||
if (maxScroll > 0 && targetElement.scrollTop < maxScroll - 1) {
|
||||
isProgrammaticScroll = true;
|
||||
targetElement.scrollTop = maxScroll;
|
||||
}
|
||||
}
|
||||
|
|
@ -1091,6 +1094,7 @@ document.fonts.addEventListener("loadingdone", (event) => {
|
|||
if (!window.isScrolled) {
|
||||
const maxScroll = targetElement.scrollHeight - targetElement.clientHeight;
|
||||
if (targetElement.scrollTop < maxScroll - 5) {
|
||||
isProgrammaticScroll = true;
|
||||
targetElement.scrollTop = maxScroll;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue