Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/17902

Danielc49b51b4e5b0
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts
index a95be3021f..bcc83ed032 100644
--- a/app/src/menus/protyle.ts
+++ b/app/src/menus/protyle.ts
@@ -946,6 +946,14 @@ export const zoomOut = (options: {
if (options.protyle.options.backlinkData) {
return;
}
+ // 退出聚焦可能连续触发多次 zoomOut(如列表圆点点击 + 面包屑退出聚焦),
+ // 前次 onGet 会把 scrollTop 重置为 0,因此用 protyle 实例保存首次的正确值供后续复用,
+ // 仅当 scrollTop > 0 时更新,避免被 onGet 重置的 0 覆盖;退出聚焦完成后清除
+ // https://github.com/siyuan-note/siyuan/issues/17902
+ if (options.protyle.contentElement.scrollTop > 0) {
+ (options.protyle as any)._zoomOutSavedScrollTop = options.protyle.contentElement.scrollTop;
+ }
+ const savedScrollTop = (options.protyle as any)._zoomOutSavedScrollTop ?? options.protyle.contentElement.scrollTop;
if (typeof options.isPushBack === "undefined") {
options.isPushBack = true;
}
@@ -1003,11 +1011,16 @@ export const zoomOut = (options: {
scrollAttr: options.focusId ? {
rootId: options.id,
focusId: options.focusId,
- // 使用失焦前保存的滚动位置,避免 innerHTML 重载后 scrollTop 归零
- // https://github.com/siyuan-note/siyuan/issues/17886
- scrollTop: (options.protyle as any).scrollTopBeforeBlur ?? options.protyle.contentElement.scrollTop
+ scrollTop: savedScrollTop
} : undefined,
- afterCB: options.callback,
+ afterCB: () => {
+ if (options.focusId) {
+ (options.protyle as any)._zoomOutSavedScrollTop = undefined;
+ }
+ if (options.callback) {
+ options.callback();
+ }
+ },
});
// https://github.com/siyuan-note/siyuan/issues/4874
if (options.focusId) {
@@ -1090,6 +1103,11 @@ export const zoomOut = (options: {
data: getFocusResponse,
protyle: options.protyle,
action: options.isPushBack ? [Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_UNUNDO],
+ scrollAttr: {
+ rootId: options.id,
+ focusId: options.focusId,
+ scrollTop: savedScrollTop
+ }
});
});
return;
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 40cb8c437e..7b292a906f 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -1949,9 +1949,6 @@ export class WYSIWYG {
const range = getSelection().getRangeAt(0);
if (this.element === range.startContainer || this.element.contains(range.startContainer)) {
protyle.toolbar.range = range.cloneRange();
- // 失焦前保存滚动位置,供 zoomOut 在重载后恢复,防止浏览器焦点切换导致 scrollTop 归零
- // https://github.com/siyuan-note/siyuan/issues/17886
- (protyle as any).scrollTopBeforeBlur = protyle.contentElement.scrollTop;
}
});