An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Avoid loading entire documents from incomplete scroll positions https://github.com/siyuan-note/siyuan/issues/12696
Daniel97427bfa676c
diff --git a/app/src/protyle/scroll/saveScroll.ts b/app/src/protyle/scroll/saveScroll.tsindex d2d761009e..201a455c34 100644--- a/app/src/protyle/scroll/saveScroll.ts+++ b/app/src/protyle/scroll/saveScroll.ts@@ -7,6 +7,7 @@ import {setStorageVal} from "../util/compatibility";import {isSupportCSSHL} from "../render/searchMarkRender";import {isEncryptedBox} from "../../util/pathName";import {getContenteditableElement} from "../wysiwyg/getBlock";+import {getSavedScrollRange, getScrollRequestParams} from "./scrollRequest";export const saveScroll = (protyle: IProtyle, getObject = false) => {if (!protyle.wysiwyg.element.firstElementChild || window.siyuan.config.readonly ||@@ -16,8 +17,10 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {}const attr: IScrollAttr = {rootId: protyle.block.rootID,- startId: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),- endId: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),+ ...getSavedScrollRange(+ protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),+ protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),+ ),scrollTop: protyle.contentElement.scrollTop || parseInt(protyle.contentElement.getAttribute("data-scrolltop")) || 0,};let range: Range;@@ -133,6 +136,7 @@ export const getDocByScroll = (options: {if (response.code === 1) {const getDocParam: Record<string, any> = {id: options.scrollAttr.rootId || options.mergedOptions?.blockId || options.protyle.block?.rootID || options.scrollAttr.startId,+ ...getScrollRequestParams(window.siyuan.config.editor.dynamicLoadBlocks),query: options.protyle.query?.key,queryMethod: options.protyle.query?.method,queryTypes: options.protyle.query?.types,@@ -162,8 +166,11 @@ export const getDocByScroll = (options: {}const getDocParam: Record<string, any> = {id: options.scrollAttr?.rootId || options.mergedOptions?.blockId || options.protyle.block?.rootID || options.scrollAttr?.startId,- startID: options.scrollAttr?.startId,- endID: options.scrollAttr?.endId,+ ...getScrollRequestParams(+ window.siyuan.config.editor.dynamicLoadBlocks,+ options.scrollAttr?.startId,+ options.scrollAttr?.endId,+ ),query: options.protyle.query?.key,queryMethod: options.protyle.query?.method,queryTypes: options.protyle.query?.types,diff --git a/app/src/protyle/scroll/scrollRequest.test.ts b/app/src/protyle/scroll/scrollRequest.test.tsnew file mode 100644index 0000000000..46c5b71dec--- /dev/null+++ b/app/src/protyle/scroll/scrollRequest.test.ts@@ -0,0 +1,32 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {getSavedScrollRange, getScrollRequestParams} from "./scrollRequest";++describe("getSavedScrollRange", () => {+ it("keeps a complete range", () => {+ assert.deepEqual(getSavedScrollRange("first", "last"), {+ startId: "first",+ endId: "last",+ });+ });++ it("discards an incomplete range", () => {+ assert.deepEqual(getSavedScrollRange(null, "last"), {});+ assert.deepEqual(getSavedScrollRange("first", null), {});+ });+});++describe("getScrollRequestParams", () => {+ it("keeps the configured size and a complete saved range", () => {+ assert.deepEqual(getScrollRequestParams(192, "first", "last"), {+ size: 192,+ startID: "first",+ endID: "last",+ });+ });++ it("keeps the configured size when discarding an incomplete range", () => {+ assert.deepEqual(getScrollRequestParams(192, null, "last"), {size: 192});+ assert.deepEqual(getScrollRequestParams(192, "first", null), {size: 192});+ });+});diff --git a/app/src/protyle/scroll/scrollRequest.ts b/app/src/protyle/scroll/scrollRequest.tsnew file mode 100644index 0000000000..52211443c9--- /dev/null+++ b/app/src/protyle/scroll/scrollRequest.ts@@ -0,0 +1,20 @@+export const getSavedScrollRange = (startId?: string | null, endId?: string | null): {+ startId?: string,+ endId?: string,+} => {+ if (!startId || !endId) {+ return {};+ }+ return {startId, endId};+};++export const getScrollRequestParams = (size: number, startID?: string | null, endID?: string | null): {+ size: number,+ startID?: string,+ endID?: string,+} => {+ if (!startID || !endID) {+ return {size};+ }+ return {size, startID, endID};+};