From 8ec4dae062752f06ac6f348492a9fb31cfb46cad Mon Sep 17 00:00:00 2001 From: gramps Date: Tue, 14 Jul 2026 14:17:57 -0700 Subject: [PATCH] fix scroll: rAF for layout-safe scrollHeight, direction-aware _userScrolledAway --- templates/index.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/templates/index.html b/templates/index.html index 27c38a2..1464f50 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1155,7 +1155,7 @@ async function loadConversation(convId) { container.innerHTML = ''; conversationHistory = []; data.messages.forEach(msg => { appendMessage(msg.role, msg.content, false, false, null, msg.perplexity); conversationHistory.push({ role: msg.role, content: msg.content }); }); - scrollToLatest(); + scrollToLatest(); await loadConversations(); } catch(e) {} } @@ -1650,7 +1650,11 @@ function toggleDirection() { } let _userScrolledAway = false; document.getElementById('chatContainer')?.addEventListener('scroll', function() { - _userScrolledAway = this.scrollTop > 100; + if (_waterfallDirection === 'newest') { + _userScrolledAway = this.scrollTop > 100; + } else { + _userScrolledAway = this.scrollTop < this.scrollHeight - this.clientHeight - 60; + } }, { passive: true }); function scrollToLatest() { const c = document.getElementById('chatContainer'); @@ -1659,7 +1663,11 @@ function scrollToLatest() { if (_userScrolledAway) return; c.scrollTop = 0; } else { - c.scrollTop = c.scrollHeight; + if (_userScrolledAway) return; + requestAnimationFrame(() => { + const cc = document.getElementById('chatContainer'); + if (cc) cc.scrollTop = cc.scrollHeight; + }); } } function resetScrollLock() { _userScrolledAway = false; }