feat: auto-scroll deaktivieren beim hochscrollen, reaktivieren am Ende

This commit is contained in:
Meleki committed 2026-03-11 11:31:41 +01:00
1 parent bdb7f54c74
commit b45abab0aa
3 files changed
+32 -1

No files matched your search

+2
View File
@@ -170,6 +170,7 @@ async function clearChat() {
loadedArchiveCount = 0;
_oldestLoadedSortKey = 0;
_hasMoreOlderMessages = false;
_autoScroll = true;
clearReply();
setMeta(`Archiviert: ${archive.chainCount} Chains, ${archive.messageCount} Messages`);
@@ -346,6 +347,7 @@ async function sendMessage() {
}
addUserBubble(bubbleText, true, '', null, false, null, inlineImages);
scrollDownForce(); // Beim Senden immer nach unten
input.value = '';
input.dispatchEvent(new Event('input'));
+5 -1
View File
@@ -68,6 +68,9 @@ async function loadHistory() {
try {
const sid = getCurrentSessionId();
// Auto-Scroll initialisieren (einmalig pro Session-Load)
initAutoScroll();
const data = await apiHistory(sid, null, isDeletedVisible());
const entries = data.entries || [];
@@ -90,7 +93,8 @@ async function loadHistory() {
if (entry.chain) addChainMetaBubble(entry.chain, false);
}
scrollDown();
// Beim initialen Laden immer ganz nach unten scrollen
scrollDownForce();
setMeta('Bereit');
startHistoryPolling();
} catch (e) {
+25
View File
@@ -14,11 +14,36 @@ function truncate(s, max) {
return s && s.length > max ? s.substring(0, max) + '...' : (s || '');
}
// Auto-Scroll: wird deaktiviert wenn User nach oben scrollt, reaktiviert wenn er ganz unten ist
var _autoScroll = true;
function initAutoScroll() {
const chat = chatEl();
if (!chat) return;
_autoScroll = true;
chat.addEventListener('scroll', function() {
const threshold = 60;
const atBottom = chat.scrollHeight - chat.scrollTop - chat.clientHeight <= threshold;
_autoScroll = atBottom;
});
}
function scrollDown() {
const chat = chatEl();
if (!chat) return;
if (!_autoScroll) return;
chat.scrollTop = chat.scrollHeight;
// Nach Font-Swap kann sich die Höhe ändern → nochmal scrollen
document.fonts.ready.then(() => {
if (_autoScroll) chat.scrollTop = chat.scrollHeight;
});
}
function scrollDownForce() {
const chat = chatEl();
if (!chat) return;
_autoScroll = true;
chat.scrollTop = chat.scrollHeight;
document.fonts.ready.then(() => {
chat.scrollTop = chat.scrollHeight;
});