修复聊天室滚屏开关失效
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user