Merge pull request #2546 from SillyTavern/scrollsnap Improve auto-scroll snapping

b3c2f37a0c041f6644e010f528cf6f870505e937

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +20 -6Ignore whitespace
public/script.js+20 -6
@@ -9253,12 +9253,26 @@ jQuery(async function () {
92539253 }
92549254 });
92559255 const chatElementScroll = document.getElementById('chat');
92569256 chatElementScroll.addEventListener('wheel',const chatScrollHandler = function () {
9257- scrollLock = true;
9257+ if (power_user.waifuMode) {
9258- }, { passive: true });
9258+ scrollLock = true;
9259- chatElementScroll.addEventListener('touchstart', function () {
9259+ return;
9260- scrollLock = true;
9260+ }
9261- }, { passive: true });
9261+
9262+ const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 1;
9263+
9264+ // Resume autoscroll if the user scrolls to the bottom
9265+ if (scrollLock && scrollIsAtBottom) {
9266+ scrollLock = false;
9267+ }
9268+
9269+ // Cancel autoscroll if the user scrolls up
9270+ if (!scrollLock && !scrollIsAtBottom) {
9271+ scrollLock = true;
9272+ }
9273+ };
9274+ chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true });
9275+ chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true });
92629276 chatElementScroll.addEventListener('scroll', function () {
92639277 if (is_use_scroll_holder) {
92649278 this.scrollTop = scroll_holder;