Merge pull request #2546 from SillyTavern/scrollsnap

Improve auto-scroll snapping
This commit is contained in:
Cohee 2024-07-23 15:55:00 +03:00 committed by GitHub
commit b3c2f37a0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 6 deletions

View File

@ -9253,12 +9253,26 @@ jQuery(async function () {
}
});
const chatElementScroll = document.getElementById('chat');
chatElementScroll.addEventListener('wheel', function () {
const chatScrollHandler = function () {
if (power_user.waifuMode) {
scrollLock = true;
}, { passive: true });
chatElementScroll.addEventListener('touchstart', function () {
return;
}
const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 1;
// Resume autoscroll if the user scrolls to the bottom
if (scrollLock && scrollIsAtBottom) {
scrollLock = false;
}
// Cancel autoscroll if the user scrolls up
if (!scrollLock && !scrollIsAtBottom) {
scrollLock = true;
}, { passive: true });
}
};
chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true });
chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true });
chatElementScroll.addEventListener('scroll', function () {
if (is_use_scroll_holder) {
this.scrollTop = scroll_holder;