An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/17886
Daniela20f27a7452c
diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.tsindex 6263b57a4d..f5a03c8d4c 100644--- a/app/src/menus/protyle.ts+++ b/app/src/menus/protyle.ts@@ -1000,6 +1000,13 @@ export const zoomOut = (options: {data: getResponse,protyle: options.protyle,action,+ 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+ } : undefined,afterCB: options.callback,});// https://github.com/siyuan-note/siyuan/issues/4874@@ -1023,12 +1030,43 @@ export const zoomOut = (options: {showElement = getFirstBlock(showElement);}focusBlock(showElement);+ // 加强定位,使用 AbortController 监听用户手势,一旦用户主动滚动即停止强制定位,+ // 否则数据库等异步渲染块撑高内容时会反复重置滚动位置+ // https://github.com/siyuan-note/siyuan/issues/17886+ const userScrollAbort = new AbortController();+ const onUserScroll = () => userScrollAbort.abort();+ // 程序化滚动标志,避免 ResizeObserver 自身的 scrollCenter 触发 scroll 事件后误中止+ let observerScrollProgrammatic = false;+ options.protyle.contentElement.addEventListener("wheel", onUserScroll,+ {capture: true, signal: userScrollAbort.signal});+ options.protyle.contentElement.addEventListener("touchstart", onUserScroll,+ {capture: true, signal: userScrollAbort.signal});+ options.protyle.contentElement.addEventListener("touchmove", onUserScroll,+ {capture: true, signal: userScrollAbort.signal});+ options.protyle.contentElement.addEventListener("keydown", (event: KeyboardEvent) => {+ if (["PageUp", "PageDown", "Home", "End", "ArrowUp", "ArrowDown", " "].includes(event.key)) {+ userScrollAbort.abort();+ }+ }, {capture: true, signal: userScrollAbort.signal});+ options.protyle.contentElement.addEventListener("scroll", () => {+ if (observerScrollProgrammatic) {+ return;+ }+ userScrollAbort.abort();+ }, {capture: true, signal: userScrollAbort.signal});const resizeObserver = new ResizeObserver(() => {+ if (userScrollAbort.signal.aborted) {+ resizeObserver.disconnect();+ return;+ }+ observerScrollProgrammatic = true;scrollCenter(options.protyle, focusElement, "start");+ observerScrollProgrammatic = false;});resizeObserver.observe(options.protyle.wysiwyg.element);setTimeout(() => {resizeObserver.disconnect();+ userScrollAbort.abort();}, 1000 * 3);} else if (!options.focusId) {fetchPost("/api/filetree/getDoc", {diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex 08fb890117..33cd853eaf 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -204,6 +204,12 @@ const setHTML = (options: {}} else {protyle.wysiwyg.element.innerHTML = options.content;+ // 设置 innerHTML 会导致浏览器将 scrollTop 重置为 0,此处立即恢复以避免页面跳转到开头+ // https://github.com/siyuan-note/siyuan/issues/17886+ if (options.scrollAttr && typeof options.scrollAttr.scrollTop === "number") {+ protyle.contentElement.scrollTop = options.scrollAttr.scrollTop;+ protyle.scroll.lastScrollTop = options.scrollAttr.scrollTop;+ }}/// #if MOBILEdiff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 8e9c5ca89d..013b6cf86b 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -1902,6 +1902,9 @@ 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;}});