修复聊天室滚屏开关失效

This commit is contained in:
pllx
2026-04-30 15:19:38 +08:00
parent 8c7b1086ff
commit b21f583fe5
6 changed files with 70 additions and 10 deletions
+39 -1
View File
@@ -75,10 +75,46 @@ export function localClearScreen(roomId = window.chatContext?.roomId, maxMessage
if (publicPane) {
publicPane.appendChild(notice);
publicPane.scrollTop = publicPane.scrollHeight;
scrollChatToBottom(publicPane, isAutoScrollEnabled);
}
}
/**
* 读取当前是否允许聊天窗口自动滚屏。
*
* @returns {boolean}
*/
export function isAutoScrollEnabled() {
const state = window.chatState;
if (state && typeof state.autoScroll !== "undefined") {
return Boolean(state.autoScroll);
}
const checkbox = document.getElementById("auto_scroll");
return checkbox ? Boolean(checkbox.checked) : true;
}
/**
* 写入自动滚屏状态,并同步页面复选框和状态文字。
*
* @param {boolean} enabled 是否开启自动滚屏
* @returns {boolean}
*/
export function setAutoScrollEnabled(enabled) {
const nextEnabled = Boolean(enabled);
const state = window.chatState;
if (state) {
state.autoScroll = nextEnabled;
}
syncAutoScrollControls(nextEnabled);
return nextEnabled;
}
/**
* 同步自动滚屏复选框与状态文字。
*
@@ -111,6 +147,8 @@ export function toggleAutoScroll(getCurrent, setCurrent) {
if (typeof setCurrent === "function") {
setCurrent(nextEnabled);
} else {
setAutoScrollEnabled(nextEnabled);
}
syncAutoScrollControls(nextEnabled);