Skip to content

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

:bug: Keep mind map controls within the visible editor https://github.com/siyuan-note/siyuan/issues/20873

Daniel218614a9bab6
diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scss
index 1bd70c835f..de430be4f9 100644
--- a/app/src/assets/scss/protyle/_mindmap-view.scss
+++ b/app/src/assets/scss/protyle/_mindmap-view.scss
@@ -1037,6 +1037,7 @@
z-index: 7;
display: flex;
flex-direction: column;
+ width: max-content;
max-width: calc(100% - 16px);
gap: 4px;
padding: 8px;
diff --git a/app/src/protyle/render/listMindmap/arrows.test.ts b/app/src/protyle/render/listMindmap/arrows.test.ts
index 9089b83f8f..40fb18acab 100644
--- a/app/src/protyle/render/listMindmap/arrows.test.ts
+++ b/app/src/protyle/render/listMindmap/arrows.test.ts
@@ -317,6 +317,7 @@ test("the shared direction selector preserves focus and only patches arrow direc
Object.assign(target, {
inspector: new Control("div"), selectedRelation: "r", model: {metadata: {relations: [relation]}},
label: (key: string) => key,
+ queueInspectorLayout: () => {},
makeButton: () => {
const button = new Control("button");
button.append(new Control("svg"));
diff --git a/app/src/protyle/render/listMindmap/inspector.test.ts b/app/src/protyle/render/listMindmap/inspector.test.ts
new file mode 100644
index 0000000000..76d14544b6
--- /dev/null
+++ b/app/src/protyle/render/listMindmap/inspector.test.ts
@@ -0,0 +1,258 @@
+import * as assert from "node:assert/strict";
+import {execFile} from "node:child_process";
+import {mkdtempSync, readFileSync, rmSync, writeFileSync} from "node:fs";
+import {tmpdir} from "node:os";
+import * as path from "node:path";
+import {promisify} from "node:util";
+import test from "node:test";
+import {ScriptTarget, transpileModule} from "typescript";
+
+const browserCases = async (source: string, css: string) => {
+ const check = require("node:assert/strict");
+ const style = document.createElement("style");
+ style.textContent = css;
+ document.head.append(style);
+ const api = new Function("Constants", "mathRender", "tabsRender", "destroyTabsRender", source +
+ "; return {ListMindmapView, readListMindmap};")(
+ {CUSTOM_SY_LIST_MINDMAP_DATA: "custom-sy-list-mindmap-data"}, () => {}, () => {}, () => {});
+ const lute = Lute.New();
+ lute.SetProtyleWYSIWYG(true);
+ const frame = () => new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
+ const settle = async () => { await frame(); await frame(); await frame(); };
+ for (const mobile of [false, true]) {
+ for (const scale of [1, .75]) {
+ document.body.className = mobile ? "body--android" : "body--windows";
+ const outer = document.createElement("div");
+ outer.style.cssText = `position:absolute;top:40px;left:30px;width:${mobile ? 320 : 700}px;` +
+ `height:480px;overflow:auto;transform:scale(${scale});transform-origin:top left`;
+ const spacer = document.createElement("div");
+ const host = document.createElement("div");
+ const tail = document.createElement("div");
+ tail.style.height = "600px";
+ host.style.cssText = "--mindmap-view-height:300px;--b3-border-color:#888";
+ outer.append(spacer, host, tail);
+ document.body.append(outer);
+ const holder = document.createElement("div");
+ holder.innerHTML = lute.Md2BlockDOM("- Root\n - Node A\n - Node B\n");
+ const model = api.readListMindmap(holder.firstElementChild);
+ const original = holder.innerHTML;
+ const view = new api.ListMindmapView({host, model, onExit: () => {},
+ onNodeWidths: async () => true});
+ const inspector = host.querySelector<HTMLElement>(".mindmap-view__inspector");
+ const panel = host.querySelector<HTMLElement>(".mindmap-view__inspector-popover");
+ const viewport = host.querySelector<HTMLElement>(".mindmap-view__viewport");
+ const node = () => host.querySelector<HTMLElement>(`[data-mindmap-id="${model.root.children[0].id}"]`);
+ const select = () => view.selectNode(model.root.children[0].id);
+ const click = () => node().dispatchEvent(new MouseEvent("click", {bubbles: true}));
+ let stage = "initial";
+ const visible = (element: HTMLElement) => {
+ const rect = element.getBoundingClientRect();
+ const clip = outer.getBoundingClientRect();
+ check.equal(element.hidden, false, `${stage}: ${element.className} stays open`);
+ check.equal(getComputedStyle(element).visibility, "visible");
+ check.ok(rect.top >= clip.top - 1 && rect.bottom <= clip.bottom + 1,
+ `vertical bounds ${rect.top}..${rect.bottom} within ${clip.top}..${clip.bottom}`);
+ check.ok(rect.left >= clip.left - 1 && rect.right <= clip.right + 1);
+ };
+ await settle();
+ select();
+ await settle();
+ visible(inspector);
+ check.equal(outer.scrollTop, 0, "a fully visible map preserves document position");
+
+ spacer.style.height = "430px";
+ stage = "short";
+ await settle();
+ // 文档布局变化后,以真实滚动事件触发同一定位入口。
+ outer.dispatchEvent(new Event("scroll"));
+ await settle();
+ check.equal(getComputedStyle(inspector).visibility, "hidden", "a narrow strip cannot contain the toolbar");
+ node().dispatchEvent(new PointerEvent("pointerover", {bubbles: true, pointerType: "mouse"}));
+ await settle();
+ check.equal(outer.scrollTop, 0, "hover never scrolls the document");
+ click();
+ await settle();
+ visible(inspector);
+ check.ok(outer.scrollTop > 0, "an explicit click reveals a short map");
+ check.ok(host.getBoundingClientRect().bottom <= outer.getBoundingClientRect().bottom + 1);
+ const afterClick = outer.scrollTop;
+ click();
+ await settle();
+ check.equal(outer.scrollTop, afterClick, "repeated selection does not jump");
+
+ outer.scrollTop = 600;
+ await settle();
+ click();
+ await settle();
+ check.ok(host.getBoundingClientRect().top >= outer.getBoundingClientRect().top - 1,
+ "a short map clipped at the top is also revealed");
+ visible(inspector);
+
+ outer.scrollTop = 0;
+ view.suppressLinkClick = true;
+ click();
+ await settle();
+ check.equal(outer.scrollTop, 0, "the click following a drag does not reveal the map");
+ view.suppressLinkClick = false;
+ view.pinching = true;
+ click();
+ await settle();
+ check.equal(outer.scrollTop, 0, "pinches do not scroll the document");
+ view.pinching = false;
+ view.focusNode(model.root.children[0].id);
+ await settle();
+ visible(inspector);
+ check.ok(outer.scrollTop > 0, "keyboard node focus also reveals the short map");
+
+ spacer.style.height = "0";
+ stage = "tall";
+ host.style.setProperty("--mindmap-view-height", "1100px");
+ outer.scrollTop = 120;
+ await settle();
+ click();
+ await settle();
+ check.equal(outer.scrollTop, 120, "a tall map retains its reading position");
+ visible(inspector);
+ check.ok(Math.abs(inspector.getBoundingClientRect().bottom -
+ (outer.getBoundingClientRect().bottom - 8 * scale)) < 1);
+ for (const kind of ["color", "width"]) {
+ view.openInspectorPanel(kind, inspector.querySelector<HTMLButtonElement>(`[aria-label="${kind}"]`));
+ await settle();
+ visible(panel);
+ outer.scrollTop += 90;
+ await settle();
+ visible(inspector);
+ visible(panel);
+ check.ok(panel.getBoundingClientRect().bottom <= inspector.getBoundingClientRect().top);
+ view.closeInspectorPanel();
+ }
+
+ // 连线和概要共用同一操作栏,内容重绘也必须保留可见边界。
+ view.selectedId = undefined;
+ stage = "line";
+ view.selectedEdge = model.root.children[0].id;
+ view.renderInspector();
+ await settle();
+ visible(inspector);
+ view.selectedEdge = undefined;
+ view.model.metadata.summaries = [{id: "summary", label: "Summary", parentId: model.root.id,
+ fromId: model.root.children[0].id, toId: model.root.children[1].id}];
+ view.selectSummary("summary");
+ stage = "summary";
+ await settle();
+ visible(inspector);
+ delete view.model.metadata.summaries;
+ select();
+
+ outer.style.height = "220px";
+ stage = "resize";
+ await settle();
+ visible(inspector);
+ view.openInspectorPanel("width", inspector.querySelector<HTMLButtonElement>('[aria-label="width"]'));
+ await settle();
+ visible(panel);
+ outer.scrollTop = 1080;
+ await settle();
+ check.equal(getComputedStyle(inspector).visibility, "hidden");
+ check.equal(getComputedStyle(panel).visibility, "hidden");
+ outer.scrollTop = 300;
+ stage = "restore";
+ await settle();
+ visible(inspector);
+ visible(panel);
+
+ const clipping = document.createElement("div");
+ clipping.style.cssText = "position:absolute;inset:0;overflow:hidden;width:260px;height:200px";
+ document.body.append(clipping);
+ clipping.append(outer);
+ outer.dispatchEvent(new Event("scroll"));
+ await settle();
+ for (const control of [inspector, panel]) {
+ const rect = control.getBoundingClientRect();
+ const clip = clipping.getBoundingClientRect();
+ check.ok(rect.left >= clip.left && rect.right <= clip.right,
+ `${control.className}: horizontal bounds ${rect.left}..${rect.right} within ${clip.left}..${clip.right}; ` +
+ `scale ${scale}; ${control.style.cssText}; host ${JSON.stringify(host.getBoundingClientRect().toJSON())}`);
+ check.ok(rect.top >= clip.top && rect.bottom <= clip.bottom,
+ "nested clipping constrains both controls vertically");
+ }
+ document.body.append(outer);
+ clipping.remove();
+ outer.dispatchEvent(new Event("scroll"));
+ await settle();
+
+ const scrollBeforeFullscreen = outer.scrollTop;
+ view.enterFullscreen();
+ await settle();
+ select();
+ await settle();
+ const full = inspector.getBoundingClientRect();
+ check.ok(full.top >= 0 && full.bottom <= innerHeight);
+ view.exitFullscreen();
+ stage = "exit fullscreen";
+ await settle();
+ check.equal(outer.scrollTop, scrollBeforeFullscreen);
+ select();
+ await settle();
+ visible(inspector);
+ check.equal(holder.innerHTML, original, "overlay placement never modifies document data");
+ view.queueInspectorLayout(true);
+ view.destroy();
+ await settle();
+ check.equal(host.childElementCount, 0);
+ outer.remove();
+ check.equal(viewport.isConnected, false);
+ }
+ }
+ return "Mindmap inspector cases passed";
+};
+
+test("mindmap inspectors follow clipped viewports and reveal short maps only after selection", {
+ skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
+ timeout: 45000,
+}, async () => {
+ const source = ["../av/richTextValue.ts", "summary.ts", "connectors.ts", "appearance.ts", "model.ts", "fold.ts", "routing.ts", "pan.ts", "view.ts"]
+ .map(file => transpileModule(readFileSync(path.join(__dirname, file), "utf8")
+ .replace(/^import [\s\S]*?;\r?\n/gm, "").replace(/^export /gm, ""), {
+ compilerOptions: {target: ScriptTarget.ES2021},
+ }).outputText).join("\n");
+ const css = ["business/_block.scss", "business/_color.scss", "protyle/_mindmap-view.scss"]
+ .map(file => require("sass").compile(path.resolve(__dirname, "../../../assets/scss", file),
+ {logger: require("sass").Logger.silent}).css).join("\n");
+ const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-mindmap-inspector-"));
+ 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, width: 1000, height: 800,
+ webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true}});
+ 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; (${browserSource})(${JSON.stringify(source)}, ${JSON.stringify(css)})`)}));
+ win.destroy();
+ app.exit(0);
+ } catch (error) {
+ console.error(error);
+ win.destroy();
+ app.exit(1);
+ }
+});`, "utf8");
+ const env = {...process.env};
+ delete env.ELECTRON_RUN_AS_NODE;
+ try {
+ const result = await promisify(execFile)(require("electron") as unknown as string, [script], {
+ env, timeout: 40000, windowsHide: true,
+ });
+ assert.match(result.stdout, /Mindmap inspector cases passed/);
+ } finally {
+ assert.equal(path.dirname(path.resolve(temporary)), path.resolve(tmpdir()));
+ rmSync(temporary, {recursive: true, force: true});
+ }
+});
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 42e6862b4f..dfe38e1760 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -2632,16 +2632,19 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.ok(routeStatus.getBoundingClientRect().bottom < lineMenuBounds.top);
routeStatus.hidden = statusHidden;
hostParent.style.width = "320px";
+ await settle();
const narrowInspectorBounds = inspector.getBoundingClientRect();
const narrowPanelBounds = host.getBoundingClientRect();
check.ok(narrowInspectorBounds.left > narrowPanelBounds.left);
check.ok(narrowInspectorBounds.right < narrowPanelBounds.right);
hostParent.style.width = "180px";
+ await settle();
check.ok(inspector.scrollWidth > inspector.clientWidth, "the line menu scrolls when its actual controls no longer fit");
inspector.scrollLeft = inspector.scrollWidth;
check.ok(inspector.scrollLeft > 0);
inspector.scrollLeft = 0;
hostParent.style.width = "760px";
+ await settle();
check.equal(inspector.querySelector(".mindmap-view__section"), null);
const arrowSelector = () => inspector.querySelector<HTMLSelectElement>('[aria-label="listMindmapArrowDirection"]');
check.ok(arrowSelector().classList.contains("b3-select"));
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index e6143f18b9..5b30ef1dc1 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -137,6 +137,8 @@ export class ListMindmapView {
widths: {id: string, width: number}[], baseWidth: number, slider: number, preview: boolean,
};
private widthPending = false;
+ private inspectorFrame = 0;
+ private revealInspectorHost = false;
private readonly zoomLabel: HTMLSpanElement;
private readonly zoomSlider = createElement("input", "b3-slider");
private readonly nodeElements = new Map<string, HTMLDivElement>();
@@ -268,6 +270,26 @@ export class ListMindmapView {
this.listen(document, "pointerdown", this.dismissControls, {capture: true});
this.listen(options.host, "pointerdown", this.activatePointer, {capture: true});
this.listen(options.host, "click", this.activatePointer, {capture: true});
+ this.listen(options.host, "click", (event: MouseEvent) => {
+ const target = event.target as HTMLElement;
+ // 点击完成后再滚动文档,避免节点拖动、双指缩放和控件操作改变阅读位置。
+ if (!this.panning && !this.pinching && !this.suppressLinkClick &&
+ target.closest(".mindmap-view") === options.host && this.viewport.contains(target) &&
+ !target.closest("input, select, textarea, a, audio, video, iframe, .mindmap-view__node--editing") &&
+ (!target.closest("button") || target.closest(".mindmap-view__relation"))) {
+ this.queueInspectorLayout(true);
+ }
+ }, {capture: true});
+ this.listen(document, "scroll", (event: Event) => {
+ if (event.target === document || event.target instanceof Element && event.target.contains(options.host)) {
+ this.queueInspectorLayout();
+ }
+ }, {capture: true, passive: true});
+ this.listen(window, "resize", () => this.queueInspectorLayout());
+ if (window.visualViewport) {
+ this.listen(window.visualViewport, "resize", () => this.queueInspectorLayout());
+ this.listen(window.visualViewport, "scroll", () => this.queueInspectorLayout());
+ }
this.listen(options.host, "focusout", (event: FocusEvent) => {
if (event.relatedTarget instanceof Node && !options.host.contains(event.relatedTarget)) {
this.setInteractionActive(false);
@@ -374,22 +396,26 @@ export class ListMindmapView {
this.resizeObserver = new ResizeObserver(entries => {
this.updateToolbarLayout();
// 展开会让隐藏节点恢复尺寸;布局已测量这些节点,不应被同一尺寸的通知中断动画。
- const resized = !this.stopFoldAnimation || entries.some(({target}) => {
+ const resized = entries.some(({target}) => {
if (target === this.viewport) {
return true;
}
const element = target as HTMLElement;
const position = this.positions.get(element.dataset.mindmapId) ||
this.summaryPositions.get(element.dataset.summaryId);
- return !element.hidden && position &&
- (element.offsetWidth !== position.width || element.offsetHeight !== position.height);
+ return !element.hidden && position && (!this.stopFoldAnimation ||
+ element.offsetWidth !== position.width || element.offsetHeight !== position.height);
});
if (resized) {
this.refreshLayout();
}
- this.positionInspectorPanel();
+ this.queueInspectorLayout();
});
this.resizeObserver.observe(this.viewport);
+ // 分屏和面板调整会改变外层裁剪范围,即使画布自身尺寸没有变化也要更新浮层。
+ for (let parent = options.host.parentElement; parent; parent = parent.parentElement) {
+ this.resizeObserver.observe(parent);
+ }
this.update(this.model);
}
@@ -1155,6 +1181,7 @@ export class ListMindmapView {
this.setInteractionActive(true);
this.selectNode(id);
this.options.host.focus({preventScroll: true});
+ this.queueInspectorLayout(true);
this.revealNode(id);
}
@@ -3620,20 +3647,101 @@ export class ListMindmapView {
this.renderInspectorPanel();
}
+ private queueInspectorLayout(reveal = false) {
+ if (this.destroyed || this.inspector.hidden && !reveal) {
+ return;
+ }
+ this.revealInspectorHost ||= reveal;
+ if (this.inspectorFrame) {
+ return;
+ }
+ this.inspectorFrame = requestAnimationFrame(() => {
+ this.inspectorFrame = 0;
+ const revealHost = this.revealInspectorHost;
+ this.revealInspectorHost = false;
+ if (this.destroyed || this.inspector.hidden || this.readOnly) {
+ return;
+ }
+ if (revealHost && !this.pointer && !this.pinching && !this.fullscreenMarker) {
+ this.revealInspectorContainer();
+ }
+ this.positionInspector();
+ });
+ }
+
+ private revealInspectorContainer() {
+ // 只有能完整放入编辑区的脑图才滚动文档;高画布保持当前位置并让操作栏跟随可见区域。
+ for (let parent = this.options.host.parentElement; parent; parent = parent.parentElement) {
+ const host = this.options.host.getBoundingClientRect();
+ const clip = this.getViewportClip();
+ if (!host.height || host.height > clip.bottom - clip.top) {
+ return;
+ }
+ const delta = host.top < clip.top ? host.top - clip.top : Math.max(0, host.bottom - clip.bottom);
+ if (Math.abs(delta) < 1) {
+ return;
+ }
+ if (parent.scrollHeight > parent.clientHeight &&
+ /^(auto|scroll|overlay)$/.test(getComputedStyle(parent).overflowY)) {
+ const scale = parent.getBoundingClientRect().height / parent.offsetHeight || 1;
+ parent.scrollBy({top: delta / scale, behavior: "instant"});
+ }
+ }
+ }
+
+ private getVisibleViewportBounds() {
+ const bounds = this.viewport.getBoundingClientRect();
+ const clip = this.getViewportClip();
+ return {left: Math.max(bounds.left, clip.left), right: Math.min(bounds.right, clip.right),
+ top: Math.max(bounds.top, clip.top), bottom: Math.min(bounds.bottom, clip.bottom)};
+ }
+
+ private positionInspector() {
+ const host = this.options.host.getBoundingClientRect();
+ const visible = this.getVisibleViewportBounds();
+ const scaleX = host.width / this.options.host.offsetWidth || 1;
+ const scaleY = host.height / this.options.host.offsetHeight || 1;
+ const width = (visible.right - visible.left) / scaleX - 16;
+ this.inspector.style.maxWidth = `${Math.max(0, width)}px`;
+ this.inspector.style.left = `${((visible.left + visible.right) / 2 - host.left) / scaleX -
+ this.options.host.clientLeft}px`;
+ this.inspector.style.bottom = `${this.options.host.clientTop + this.options.host.clientHeight -
+ (visible.bottom - host.top) / scaleY + 8}px`;
+ // 可见条带放不下操作栏时保留选择,滚动回足够的空间后恢复显示。
+ this.inspector.style.visibility = width <= 0 ||
+ (visible.bottom - visible.top) / scaleY < this.inspector.offsetHeight + 16 ? "hidden" : "";
+ this.positionInspectorPanel();
+ }
+
private positionInspectorPanel() {
- if (this.inspectorPopover.hidden || !this.inspectorPanel) {
+ if (this.destroyed || this.inspectorPopover.hidden || !this.inspectorPanel) {
return;
}
const host = this.options.host.getBoundingClientRect();
+ const visible = this.getVisibleViewportBounds();
const anchor = this.inspectorPanel.anchor.getBoundingClientRect();
const scaleX = host.width / this.options.host.offsetWidth || 1;
const scaleY = host.height / this.options.host.offsetHeight || 1;
- const bottom = (host.bottom - this.inspector.getBoundingClientRect().top) / scaleY + 4;
- const left = (anchor.left + anchor.width / 2 - host.left) / scaleX - this.inspectorPopover.offsetWidth / 2;
- this.inspectorPopover.style.left = `${Math.max(8,
- Math.min(left, this.options.host.offsetWidth - this.inspectorPopover.offsetWidth - 8))}px`;
- this.inspectorPopover.style.bottom = `${bottom}px`;
- this.inspectorPopover.style.maxHeight = `${Math.max(48, this.options.host.offsetHeight - bottom - 8)}px`;
+ const bar = this.inspector.getBoundingClientRect();
+ const above = (bar.top - visible.top) / scaleY - 12;
+ const below = (visible.bottom - bar.bottom) / scaleY - 12;
+ const width = Math.max(0, (visible.right - visible.left) / scaleX - 16);
+ this.inspectorPopover.style.maxWidth = `${width}px`;
+ const height = this.inspectorPopover.scrollHeight +
+ this.inspectorPopover.offsetHeight - this.inspectorPopover.clientHeight;
+ const placeAbove = above >= height || above >= below;
+ const available = Math.max(0, placeAbove ? above : below);
+ this.inspectorPopover.style.maxHeight = `${available}px`;
+ this.inspectorPopover.style.visibility = this.inspector.style.visibility === "hidden" ||
+ !width || !available ? "hidden" : "";
+ const left = (anchor.left + anchor.width / 2 - host.left) / scaleX -
+ this.options.host.clientLeft - this.inspectorPopover.offsetWidth / 2;
+ const minLeft = (visible.left - host.left) / scaleX - this.options.host.clientLeft + 8;
+ this.inspectorPopover.style.left = `${Math.max(minLeft,
+ Math.min(left, minLeft + width - this.inspectorPopover.offsetWidth))}px`;
+ this.inspectorPopover.style.bottom = "";
+ this.inspectorPopover.style.top = `${(placeAbove ? bar.top - host.top : bar.bottom - host.top) / scaleY -
+ this.options.host.clientTop + (placeAbove ? -4 - this.inspectorPopover.offsetHeight : 4)}px`;
}
private previewNodeWidths(widths: {id: string, width: number}[]) {
@@ -3813,6 +3921,7 @@ export class ListMindmapView {
if (this.inspector.hidden || this.readOnly) {
return;
}
+ this.queueInspectorLayout();
const focusArrowDirection = this.inspector.querySelector("select") === document.activeElement;
this.inspector.replaceChildren();
const lineSelected = !!this.selectedRelation || !!this.selectedEdge || !!this.selectedSummary;
@@ -4106,15 +4215,13 @@ export class ListMindmapView {
}
}
- 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);
- // 文档滚动容器可能只露出画布的一部分,进入全屏前保留实际正在阅读的区域。
+ private getViewportClip() {
+ const visual = window.visualViewport;
+ let left = visual?.offsetLeft || 0;
+ let right = Math.min(window.innerWidth, left + (visual?.width || window.innerWidth));
+ let top = visual?.offsetTop || 0;
+ let bottom = Math.min(window.innerHeight, top + (visual?.height || window.innerHeight));
+ // 文档滚动容器可能只露出画布的一部分,浮层和全屏取景共用实际可见边界。
for (let parent = this.viewport.parentElement; parent; parent = parent.parentElement) {
const style = getComputedStyle(parent);
const rect = parent.getBoundingClientRect();
@@ -4131,6 +4238,14 @@ export class ListMindmapView {
bottom = Math.min(bottom, start + parent.clientHeight * ratioY);
}
}
+ return {left, right, top, bottom};
+ }
+
+ 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;
+ const {left, right, top, bottom} = this.getVisibleViewportBounds();
return right > left && bottom > top ? {
x: ((left + right) / 2 - bounds.left) * scaleX,
y: (top - bounds.top) * scaleY,
@@ -4144,6 +4259,7 @@ export class ListMindmapView {
return;
}
this.destroyed = true;
+ cancelAnimationFrame(this.inspectorFrame);
this.stopFoldAnimation?.();
cancelAnimationFrame(this.drawFrame);
this.drawFrame = 0;
diff --git a/app/src/protyle/render/listMindmap/viewportFocus.test.ts b/app/src/protyle/render/listMindmap/viewportFocus.test.ts
index 34857b9563..ef25fafda9 100644
--- a/app/src/protyle/render/listMindmap/viewportFocus.test.ts
+++ b/app/src/protyle/render/listMindmap/viewportFocus.test.ts
@@ -35,7 +35,7 @@ const setup = () => {
viewport: {contains: (element: unknown) => !!element, setPointerCapture: () => {},
offsetWidth: 400, offsetHeight: 300,
getBoundingClientRect: () => ({left: 0, top: 0, right: 400, bottom: 300, width: 400, height: 300})},
- selectNode: () => {}, findLine: (): unknown => undefined, selectLine: () => {},
+ selectNode: () => {}, queueInspectorLayout: () => {}, findLine: (): unknown => undefined, selectLine: () => {},
clearSelection: () => { target.selectedId = undefined; },
boundedPan: (x: number, y: number) => ({x, y}), draw: () => drawn++,
finishThen: (action: () => void) => { finished++; target.editingId = undefined; action(); },