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: Preserve mind map view anchors across fullscreen and resizing https://github.com/siyuan-note/siyuan/issues/20694
Daniel11fa121a43e5
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.syindex b5454a43e6..a4113decac 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy@@ -8,7 +8,7 @@"title": "Formatting elements","title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;","type": "doc",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -1961,7 +1961,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091509-v1x69oc",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -2132,12 +2132,12 @@"Type": "NodeParagraph","Properties": {"id": "20261019142953-4rt40w7",- "updated": "20261021132218"+ "updated": "20261024124505"},"Children": [{"Type": "NodeText",- "Data": "Entering full screen preserves the mind map's current center and zoom. Panning and zooming in full screen affect only that full-screen view. Exiting full screen restores the document view's previous center and zoom. Node edits still take effect."+ "Data": "Resizing the document canvas preserves its center and zoom. Full-screen entry keeps the zoom and centers the view when the document canvas is shorter than the full-screen viewport; otherwise it preserves the visible top edge, accounting for document scrolling. The alignment updates as the window height changes. Full-screen panning and zooming remain temporary; exiting restores the previous document view and reading position. Node edits still take effect."}]},diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.syindex 137f7854af..21e5fb690e 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy@@ -8,7 +8,7 @@"title": "排版元素","title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);","type": "doc",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -1964,7 +1964,7 @@"HeadingLevel": 2,"Properties": {"id": "20210104091228-wdpx6ev",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -2102,12 +2102,12 @@"Type": "NodeParagraph","Properties": {"id": "20261019142953-m439ybs",- "updated": "20261021132218"+ "updated": "20261024124505"},"Children": [{"Type": "NodeText",- "Data": "进入全屏时会保留脑图当前的中心点和缩放比例。全屏中的平移和缩放仅影响本次全屏浏览,退出全屏后恢复进入前的文档视角。节点内容编辑仍正常生效。"+ "Data": "调整文档内画布尺寸时保留中心点和缩放比例。进入全屏时保留缩放比例:文档画布低于全屏视口时居中,否则按当前可见区域的顶边对齐,并随窗口高度变化实时调整。全屏中的平移和缩放仅影响本次全屏浏览,退出后恢复进入前的文档视角和阅读位置。节点内容编辑仍正常生效。"}]},diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.syindex d71febd34c..61541f5459 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy@@ -8,7 +8,7 @@"title": "排版元素","title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);","type": "doc",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -1962,7 +1962,7 @@"HeadingLevel": 2,"Properties": {"id": "20211226122008-731sqd6",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -2100,12 +2100,12 @@"Type": "NodeParagraph","Properties": {"id": "20261019142953-9ypjmtz",- "updated": "20261021132218"+ "updated": "20261024124505"},"Children": [{"Type": "NodeText",- "Data": "進入全螢幕時會保留心智圖目前的中心點和縮放比例。全螢幕中的平移和縮放僅影響本次全螢幕瀏覽,離開全螢幕後恢復進入前的文件視角。節點內容編輯仍正常生效。"+ "Data": "調整文件內畫布尺寸時保留中心點和縮放比例。進入全螢幕時保留縮放比例:文件畫布低於全螢幕視口時置中,否則依目前可見區域的頂邊對齊,並隨視窗高度變化即時調整。全螢幕中的平移和縮放僅影響本次全螢幕瀏覽,離開後恢復進入前的文件視角和閱讀位置。節點內容編輯仍正常生效。"}]},diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.syindex fef54164a9..106dfc0f8e 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy@@ -9,7 +9,7 @@"title": "書式要素","title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;","type": "doc",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -2090,7 +2090,7 @@"Properties": {"ID": "20240530101000-ch5e4vh","id": "20240530101000-1ev7xub",- "updated": "20261024124323"+ "updated": "20261024124505"},"Children": [{@@ -2241,12 +2241,12 @@"Type": "NodeParagraph","Properties": {"id": "20261019142953-j4zhvo2",- "updated": "20261021132218"+ "updated": "20261024124505"},"Children": [{"Type": "NodeText",- "Data": "全画面表示に切り替えると、マインドマップの現在の中心と拡大率が維持されます。全画面表示中の移動と拡大・縮小は、その全画面表示にのみ適用されます。全画面表示を終了すると、文書内の表示は切り替え前の中心と拡大率に戻ります。ノードの編集内容は引き続き反映されます。"+ "Data": "文書内のキャンバスをリサイズしても、中心と拡大率は維持されます。全画面表示に切り替える際も拡大率を維持し、文書内のキャンバスが全画面の表示領域より低い場合は中央に、同じ高さ以上の場合は現在見えている領域の上端に合わせます。この位置合わせはウィンドウの高さに応じて更新されます。全画面表示中の移動と拡大・縮小は一時的なもので、終了すると文書内の表示範囲とスクロール位置が切り替え前に戻ります。ノードの編集内容は引き続き反映されます。"}]},diff --git a/app/src/protyle/render/listMindmap/arrows.test.ts b/app/src/protyle/render/listMindmap/arrows.test.tsindex 85c2067a8c..99a0a1119e 100644--- a/app/src/protyle/render/listMindmap/arrows.test.ts+++ b/app/src/protyle/render/listMindmap/arrows.test.ts@@ -12,8 +12,9 @@ const source = createSourceFile("view.ts", readFileSync("src/protyle/render/listScriptTarget.ES2021, true);const view = source.statements.find(item => isClassDeclaration(item) && item.name?.text === "ListMindmapView");assert.ok(view && isClassDeclaration(view));-const methods = view.members.filter(item => ["relationPath", "draw", "findLine", "renderInspector"].includes(item.name?.getText(source)));-assert.equal(methods.length, 4);+const methods = view.members.filter(item => ["relationPath", "draw", "resizeViewport", "getViewportAnchorY", "findLine", "renderInspector"]+ .includes(item.name?.getText(source)));+assert.equal(methods.length, 6);const compiled = transpileModule(`class View {${methods.map(item => item.getText(source)).join("\n")}}diff --git a/app/src/protyle/render/listMindmap/fullscreen.test.ts b/app/src/protyle/render/listMindmap/fullscreen.test.tsindex c66c23ff0f..7f232bc137 100644--- a/app/src/protyle/render/listMindmap/fullscreen.test.ts+++ b/app/src/protyle/render/listMindmap/fullscreen.test.ts@@ -19,6 +19,11 @@ const browserCases = async (source: string, css: string) => {lute.SetProtyleWYSIWYG(true);const frame = () => new Promise<void>(resolve => requestAnimationFrame(() => resolve()));const settle = async () => { await frame(); await frame(); await frame(); };+ const resizeWindow = async (width: number, height: number) => {+ await require("electron").ipcRenderer.invoke("mindmap-fullscreen-size", width, height);+ await settle();+ };+ const originalWindow = {width: innerWidth, height: innerHeight};for (const mobile of [false, true]) {for (const dark of [false, true]) {document.body.className = mobile ? "body--android" : "body--windows";@@ -137,6 +142,123 @@ const browserCases = async (source: string, css: string) => {equalCenter(beforeResize);check.equal(view.scale, beforeResizeScale, "resizing the document restores its logical center and zoom");+ const originalParentStyle = parent.style.cssText;+ const originalHeight = host.style.getPropertyValue("--mindmap-view-height");+ const beforeDocumentResize = center();+ parent.style.width = `${mobile ? 400 : 620}px`;+ host.style.setProperty("--mindmap-view-height", `${mobile ? 340 : 500}px`);+ await settle();+ equalCenter(beforeDocumentResize);+ parent.style.cssText = originalParentStyle;+ host.style.setProperty("--mindmap-view-height", originalHeight);+ await settle();+ equalCenter(beforeDocumentResize);++ // 原生窗口宽度变化保留全屏取景,退出仍恢复独立保存的文档视角。+ parent.style.width = "calc(100vw - 80px)";+ await settle();+ const documentBeforeWindowResize = center();+ button("fullscreen").click();+ await settle();+ viewport.dispatchEvent(new WheelEvent("wheel", {deltaX: 24, deltaY: 16, bubbles: true, cancelable: true}));+ const fullBeforeWindowResize = center();+ await resizeWindow(originalWindow.width - 120, originalWindow.height);+ equalCenter(fullBeforeWindowResize);+ button("exitFullscreen").click();+ await settle();+ equalCenter(documentBeforeWindowResize);+ await resizeWindow(originalWindow.width, originalWindow.height);+ equalCenter(documentBeforeWindowResize);++ // 在临界高度两侧往返,中心与顶部锚点连续衔接,全屏的缩放和平移不回写文档。+ await resizeWindow(900, 700);+ host.style.setProperty("--mindmap-view-height", "480px");+ await settle();+ const beforeHeightChanges = center();+ const savedScale = view.scale;+ const documentHeight = viewport.clientHeight;+ button("fullscreen").click();+ await settle();+ equalCenter(beforeHeightChanges);+ view.zoomAt(1.6);+ viewport.dispatchEvent(new WheelEvent("wheel", {deltaX: 20, deltaY: 10, bubbles: true, cancelable: true}));+ const reference = () => [(viewport.clientWidth / 2 - view.offsetX) / view.scale,+ (Math.max(viewport.clientHeight, documentHeight) / 2 - view.offsetY) / view.scale];+ const fullReference = reference();+ for (const height of [520, 480, 479, 320, 479, 480, 520, 700]) {+ const oldHeight = viewport.clientHeight;+ const oldOffset = view.offsetY;+ await resizeWindow(900, height);+ reference().forEach((value, index) => check.ok(Math.abs(value - fullReference[index]) < 1e-8,+ "live height changes preserve the fullscreen reference without resetting its pan or zoom"));+ if (oldHeight <= documentHeight && viewport.clientHeight <= documentHeight) {+ check.equal(view.offsetY, oldOffset, "short fullscreen viewports retain their top reference");+ }+ check.equal(view.scale, 1.6);+ check.equal(view.documentView.scale, savedScale);+ check.deepEqual([view.documentView.center.x, view.documentView.center.y], beforeHeightChanges);+ }+ button("exitFullscreen").click();+ await settle();+ equalCenter(beforeHeightChanges);+ check.equal(view.scale, savedScale);++ // 滚动容器只露出高画布的一部分时,把正在看的节点保留在全屏顶部内。+ await resizeWindow(900, 600);+ host.style.setProperty("--mindmap-view-height", "1100px");+ await settle();+ {+ const id = view.model.root.children[0].id;+ const node = host.querySelector<HTMLElement>(`[data-mindmap-id="${id}"]`);+ view.offsetY = 24 - view.positions.get(id).y * view.scale;+ view.draw();+ const tallCenter = center();+ const top = node.getBoundingClientRect().top - viewport.getBoundingClientRect().top;+ button("fullscreen").click();+ await settle();+ check.ok(Math.abs(node.getBoundingClientRect().top - top) < 1,+ "a tall canvas keeps its visible top content when entering a shorter fullscreen viewport");+ button("exitFullscreen").click();+ await settle();+ equalCenter(tallCenter);+ }+ parent.style.height = "260px";+ parent.style.overflow = "auto";+ const following = document.createElement("div");+ following.style.height = "1800px";+ parent.append(following);+ await settle();+ parent.scrollTop = 180;+ const firstId = view.model.root.children[0].id;+ const first = host.querySelector<HTMLElement>(`[data-mindmap-id="${firstId}"]`);+ const visibleTop = parent.getBoundingClientRect().top + parent.clientTop;+ const clippedTop = visibleTop - viewport.getBoundingClientRect().top;+ view.offsetY = clippedTop + 24 - view.positions.get(firstId).y * view.scale;+ view.draw();+ const scrolledCenter = center();+ const scrolledScale = view.scale;+ const nodeBeforeFullscreen = first.getBoundingClientRect();+ check.ok(nodeBeforeFullscreen.top >= visibleTop && nodeBeforeFullscreen.bottom <= visibleTop + parent.clientHeight);+ button("fullscreen").click();+ await settle();+ const fullNode = first.getBoundingClientRect();+ check.ok(fullNode.top >= viewport.getBoundingClientRect().top && fullNode.bottom <= viewport.getBoundingClientRect().bottom,+ "a node visible in a clipped tall document remains visible after entering fullscreen");+ check.ok(Math.abs(fullNode.top - (nodeBeforeFullscreen.top - visibleTop)) < 1,+ "tall fullscreen entry aligns the visible document top rather than its hidden center");+ view.zoomAt(1.8);+ button("exitFullscreen").click();+ await settle();+ equalCenter(scrolledCenter);+ check.equal(view.scale, scrolledScale);+ check.ok(Math.abs(first.getBoundingClientRect().top - nodeBeforeFullscreen.top) < 1,+ JSON.stringify({scrollTop: parent.scrollTop, before: nodeBeforeFullscreen.top,+ after: first.getBoundingClientRect().top, viewportTop: viewport.getBoundingClientRect().top}));+ following.remove();+ parent.style.cssText = originalParentStyle;+ host.style.setProperty("--mindmap-view-height", originalHeight);+ await resizeWindow(originalWindow.width, originalWindow.height);+const beforeEdit = center();const beforeEditScale = view.scale;button("fullscreen").click();@@ -185,7 +307,7 @@ const browserCases = async (source: string, css: string) => {return "Mindmap fullscreen cases passed";};-test("fullscreen preserves entry focus and restores the document viewport without reverting content updates", {+test("fullscreen preserves entry focus across viewport resizing and clipping without reverting content updates", {skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,timeout: 30000,}, async () => {@@ -199,16 +321,20 @@ test("fullscreen preserves entry focus and restores the document viewport withouconst temporary = mkdtempSync(path.join(tmpdir(), "siyuan-mindmap-fullscreen-"));const script = path.join(temporary, "run.cjs");const lute = path.resolve(__dirname, "../../../../stage/protyle/js/lute/lute.min.js");+ const browserSource = transpileModule(`(${browserCases.toString()})`, {+ compilerOptions: {target: ScriptTarget.ES2021},+ }).outputText.trim().replace(/^"use strict";\s*/, "").replace(/;$/, "");writeFileSync(script, `const {app, BrowserWindow} = require("electron");app.setPath("userData", ${JSON.stringify(path.join(temporary, "profile"))});app.commandLine.appendSwitch("disable-gpu");app.whenReady().then(async () => {const win = new BrowserWindow({show: false, webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true}});+ require("electron").ipcMain.handle("mindmap-fullscreen-size", (_event, width, height) => win.setContentSize(width, height));try {await win.loadURL("data:text/html,<html><body></body></html>");await win.webContents.executeJavaScript(require("node:fs").readFileSync(${JSON.stringify(lute)}, "utf8"));console.log(await win.webContents.executeJavaScript(${JSON.stringify(- `const __name = value => value; (${browserCases.toString()})(${JSON.stringify(source)}, ${JSON.stringify(css)})`)}));+ `const __name = value => value; (${browserSource})(${JSON.stringify(source)}, ${JSON.stringify(css)})`)}));win.destroy();app.exit(0);} catch (error) {diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex fe437e93b3..7ce3cd7bba 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -88,8 +88,10 @@ test("compact view spacing retains draggable relations without expanding unrelatconst source = typescript.createSourceFile("view.ts", readFileSync(path.join(__dirname, "view.ts"), "utf8"),typescript.ScriptTarget.ES2021, true);const declaration = source.statements.find(typescript.isClassDeclaration);- const refresh = declaration.members.find(member => member.name?.getText(source) === "refreshLayout");- const compiled = typescript.transpileModule(`class View {${refresh.getText(source)}} globalThis.View = View;`, {+ const methods = declaration.members.filter(member =>+ ["refreshLayout", "resizeViewport", "getViewportAnchorY"].includes(member.name?.getText(source)));+ assert.equal(methods.length, 3);+ const compiled = typescript.transpileModule(`class View {${methods.map(member => member.getText(source)).join("\n")}} globalThis.View = View;`, {compilerOptions: {target: typescript.ScriptTarget.ES2021},}).outputText;let frame: () => void;diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex 1440efb58e..7f9f2d1a2e 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -200,8 +200,10 @@ export class ListMindmapView {private destroyed = false;private readonly resizeObserver: ResizeObserver;private fullscreenMarker?: Comment;- private documentView?: {scale: number, center: {x: number, y: number}};+ private documentView?: {scale: number, center: {x: number, y: number}, height: number};+ private documentScroll?: {element: HTMLElement, left: number, top: number}[];private viewportCenter?: {x: number, y: number};+ private viewportSize?: {width: number, height: number};private readonly disposers: (() => void)[] = [];private printTransform?: {scale: number, offsetX: number, offsetY: number};@@ -1114,6 +1116,7 @@ export class ListMindmapView {if (!this.viewport.clientWidth || !this.viewport.clientHeight) {return;}+ this.resizeViewport();const previousPositions = this.positions;const previousSummaries = this.summaryPositions;// 同一帧内先恢复测量,布局完成后再隐藏折叠后代,避免展开时读取到零尺寸。@@ -1254,7 +1257,7 @@ export class ListMindmapView {this.viewportCenter = undefined;if (center && !this.initialFit) {this.offsetX = this.viewport.clientWidth / 2 - center.x * this.scale;- this.offsetY = this.viewport.clientHeight / 2 - center.y * this.scale;+ this.offsetY = this.getViewportAnchorY(this.viewport.clientHeight) - center.y * this.scale;}if (this.printTransform || this.options.printLayout) {this.fitPrint();@@ -1821,11 +1824,12 @@ export class ListMindmapView {if (this.destroyed) {return;}+ const width = this.viewport.clientWidth;+ const height = this.viewport.clientHeight;+ this.resizeViewport(width, height);this.world.style.transform = `translate(${this.offsetX}px, ${this.offsetY}px) scale(${this.scale})`;this.zoomLabel.textContent = `${Math.round(this.scale * 100)}%`;this.zoomSlider.value = String(Math.round(this.scale * 100));- const width = this.viewport.clientWidth;- const height = this.viewport.clientHeight;const ratio = window.devicePixelRatio || 1;if (this.canvas.width !== Math.round(width * ratio) || this.canvas.height !== Math.round(height * ratio)) {this.canvas.width = Math.round(width * ratio);@@ -3754,10 +3758,22 @@ export class ListMindmapView {if (this.destroyed || this.fullscreenMarker) {return;}+ this.resizeViewport();this.captureViewportCenter();if (this.viewportCenter) {// 文档视角只在本次全屏期间暂存,全屏内的平移和缩放独立生效。- this.documentView = {scale: this.scale, center: this.viewportCenter};+ this.documentView = {scale: this.scale, center: this.viewportCenter, height: this.viewport.clientHeight};+ const visible = this.getVisibleViewportAnchor();+ this.viewportCenter = {+ x: this.viewportCenter.x + (visible.x - this.viewport.clientWidth / 2) / this.scale,+ y: this.viewportCenter.y + visible.y / this.scale,+ };+ }+ this.documentScroll = [];+ for (let parent = this.options.host.parentElement; parent; parent = parent.parentElement) {+ if (parent.scrollHeight > parent.clientHeight || parent.scrollWidth > parent.clientWidth) {+ this.documentScroll.push({element: parent, left: parent.scrollLeft, top: parent.scrollTop});+ }}// 移到独立容器,避免编辑器祖先的变换和裁剪改变全屏覆盖范围。this.fullscreenMarker = document.createComment("mindmap-view");@@ -3784,6 +3800,12 @@ export class ListMindmapView {this.fullscreenMarker.replaceWith(this.options.host);this.fullscreenMarker = undefined;this.fullscreenChange();+ // 重新插入高画布可能触发浏览器滚动锚定,恢复文档阅读位置而非跟随下方内容。+ this.documentScroll?.forEach(({element, left, top}) => {+ element.scrollLeft = left;+ element.scrollTop = top;+ });+ this.documentScroll = undefined;if (!this.destroyed) {this.options.host.focus({preventScroll: true});}@@ -3808,6 +3830,64 @@ export class ListMindmapView {}}+ private getViewportAnchorY(height: number) {+ // 高画布全屏时固定顶部;高度相等处两种取景方式连续衔接。+ return Math.max(height, this.fullscreenMarker ? this.documentView?.height || 0 : 0) / 2;+ }++ private resizeViewport(width = this.viewport.clientWidth, height = this.viewport.clientHeight) {+ if (!width || !height || this.printTransform || this.options.printLayout) {+ return;+ }+ const previous = this.viewportSize;+ if (previous?.width === width && previous.height === height) {+ return;+ }+ this.viewportSize = {width, height};+ if (!previous || this.initialFit || this.viewportCenter) {+ return;+ }+ const x = (width - previous.width) / 2;+ const y = this.getViewportAnchorY(height) - this.getViewportAnchorY(previous.height);+ this.offsetX += x;+ this.offsetY += y;+ if (this.pointer?.pan && !this.pointer.id) {+ this.pointer.x += x;+ this.pointer.y += y;+ }+ }++ private getVisibleViewportAnchor() {+ const bounds = this.viewport.getBoundingClientRect();+ const scaleX = bounds.width ? this.viewport.clientWidth / bounds.width : 1;+ const scaleY = bounds.height ? this.viewport.clientHeight / bounds.height : 1;+ let left = Math.max(0, bounds.left);+ let right = Math.min(window.innerWidth, bounds.right);+ let top = Math.max(0, bounds.top);+ let bottom = Math.min(window.innerHeight, bounds.bottom);+ // 文档滚动容器可能只露出画布的一部分,进入全屏前保留实际正在阅读的区域。+ for (let parent = this.viewport.parentElement; parent; parent = parent.parentElement) {+ const style = getComputedStyle(parent);+ const rect = parent.getBoundingClientRect();+ const ratioX = parent.offsetWidth ? rect.width / parent.offsetWidth : 1;+ const ratioY = parent.offsetHeight ? rect.height / parent.offsetHeight : 1;+ if (style.overflowX !== "visible") {+ const start = rect.left + parent.clientLeft * ratioX;+ left = Math.max(left, start);+ right = Math.min(right, start + parent.clientWidth * ratioX);+ }+ if (style.overflowY !== "visible") {+ const start = rect.top + parent.clientTop * ratioY;+ top = Math.max(top, start);+ bottom = Math.min(bottom, start + parent.clientHeight * ratioY);+ }+ }+ return right > left && bottom > top ? {+ x: ((left + right) / 2 - bounds.left) * scaleX,+ y: (top - bounds.top) * scaleY,+ } : {x: this.viewport.clientWidth / 2, y: 0};+ }+public destroy() {this.finishSummaryEdit?.(false);this.finishRelationEdit?.(false);