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: Keep focused mind map nodes clear of top toolbar https://github.com/siyuan-note/siyuan/issues/20594
Daniel5b66b118dcfd
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.tsindex 1a529041d5..d8cc922010 100644--- a/app/src/protyle/render/listMindmap/model.test.ts+++ b/app/src/protyle/render/listMindmap/model.test.ts@@ -1117,6 +1117,98 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,await settle();check.deepEqual([navigationView.offsetX, navigationView.offsetY], hiddenMenuTransform,"a hidden menu does not reduce the node's visible area");++ // 顶部控件按悬停、焦点和全屏的实际可见状态避让,缩放画布保持相同的局部间距。+ const navigationToolbar = navigationHost.querySelector<HTMLElement>(".mindmap-view__toolbar");+ const navigationFit = () => navigationToolbar.querySelector<HTMLButtonElement>('[aria-label="listMindmapFit"]');+ const moveNavigationPointer = async (inside: boolean) => {+ navigationHost.scrollIntoView({block: "start"});+ const bounds = navigationHost.getBoundingClientRect();+ await require("electron").ipcRenderer.invoke("mindmap-view-native-input", [{+ type: "mouseMove", x: inside ? Math.round(bounds.left + 20) : 2,+ y: inside ? Math.round(bounds.top + 100) : 2,+ }]);+ await settle();+ };+ const placeAtToolbar = (left?: number) => {+ const controlBounds = navigationFit().getBoundingClientRect();+ const viewportBounds = navigationViewport.getBoundingClientRect();+ const rect = addedNode.getBoundingClientRect();+ const scaleX = viewportBounds.width / navigationViewport.offsetWidth;+ const scaleY = viewportBounds.height / navigationViewport.offsetHeight;+ const targetLeft = left ?? Math.min(controlBounds.left, viewportBounds.right - rect.width - 16 * scaleX);+ navigationView.offsetX += (targetLeft - rect.left) / scaleX;+ navigationView.offsetY += (viewportBounds.top + 16 * scaleY - rect.top) / scaleY;+ navigationView.draw();+ };+ for (const mode of ["hover", "focus", "fullscreen"]) {+ for (const width of [760, 400, 300]) {+ const scale = width === 300 ? .5 : 1;+ navigationView.setReadOnly(width !== 400);+ navigationHost.classList.toggle("fullscreen", mode === "fullscreen");+ navigationHost.style.width = `${width}px`;+ navigationHost.style.transform = `scale(${scale})`;+ navigationView.refreshLayout();+ navigationHost.focus();+ await moveNavigationPointer(mode === "hover");+ if (mode === "focus") {+ navigationFit().focus();+ }+ check.equal(getComputedStyle(navigationToolbar).opacity, "1", `${mode} shows the toolbar`);+ placeAtToolbar();+ const before = addedNode.getBoundingClientRect();+ check.ok(before.top < navigationFit().getBoundingClientRect().bottom, "target starts behind a toolbar control");+ navigationView.refreshLayout();+ if (mode === "focus") {+ navigationView.revealNode(addedItem.dataset.nodeId);+ } else {+ navigationView.selectNode(beta);+ navigationHost.dispatchEvent(new KeyboardEvent("keydown", {+ key: "ArrowDown", bubbles: true, cancelable: true,+ }));+ }+ await settle();+ check.ok(addedNode.getBoundingClientRect().top >= navigationFit().getBoundingClientRect().bottom + 15 * scale,+ `node stays below visible toolbar controls, mode=${mode}, width=${width}`);+ }+ }+ navigationHost.classList.remove("fullscreen");+ navigationHost.style.width = "760px";+ navigationHost.style.transform = "";+ navigationView.refreshLayout();+ navigationHost.focus();+ await moveNavigationPointer(true);+ placeAtToolbar(navigationViewport.getBoundingClientRect().left + 20);+ const toolbarGapTransform = [navigationView.offsetX, navigationView.offsetY];+ check.ok(addedNode.getBoundingClientRect().right < navigationToolbar.querySelector("button").getBoundingClientRect().left);+ navigationView.focusNode(addedItem.dataset.nodeId);+ await settle();+ check.deepEqual([navigationView.offsetX, navigationView.offsetY], toolbarGapTransform,+ "the toolbar's left spacer does not obstruct a node");+ navigationToolbar.querySelector<HTMLElement>(".mindmap-view__zoom").focus();+ await moveNavigationPointer(false);+ const zoomActions = navigationToolbar.querySelector<HTMLElement>(".mindmap-view__zoom-actions");+ const zoomBounds = zoomActions.getBoundingClientRect();+ check.ok(zoomBounds.width > 0 && zoomBounds.height > 0, "focused zoom controls show their popup");+ placeAtToolbar(zoomBounds.left);+ navigationView.revealNode(addedItem.dataset.nodeId);+ await settle();+ check.ok(addedNode.getBoundingClientRect().top >= zoomActions.getBoundingClientRect().bottom + 15,+ "the visible zoom popup also leaves clearance for the node");+ navigationHost.focus();+ await moveNavigationPointer(false);+ check.equal(getComputedStyle(navigationToolbar).opacity, "0");+ placeAtToolbar();+ const hiddenToolbarTransform = [navigationView.offsetX, navigationView.offsetY];+ const hiddenToolbarNode = addedNode.getBoundingClientRect();+ const hiddenToolbarViewport = navigationViewport.getBoundingClientRect();+ check.ok(hiddenToolbarNode.left >= hiddenToolbarViewport.left + 15 &&+ hiddenToolbarNode.right <= hiddenToolbarViewport.right - 15 &&+ hiddenToolbarNode.top >= hiddenToolbarViewport.top + 15, "hidden-toolbar target starts within the viewport margins");+ navigationView.focusNode(addedItem.dataset.nodeId);+ await settle();+ check.deepEqual([navigationView.offsetX, navigationView.offsetY], hiddenToolbarTransform,+ "a hidden toolbar does not move a visible node");navigationView.destroy();navigationHost.remove();diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.tsindex a5ad5dced2..ba97cd6a88 100644--- a/app/src/protyle/render/listMindmap/view.ts+++ b/app/src/protyle/render/listMindmap/view.ts@@ -876,6 +876,22 @@ export class ListMindmapView {const marginY = 16 * scaleY;const x = rect.left < viewport.left + marginX ? viewport.left + marginX - rect.left :rect.right > viewport.right - marginX ? viewport.right - marginX - rect.right : 0;+ let top = viewport.top + marginY;+ const toolbarStyle = getComputedStyle(this.toolbar);+ // 顶部仅避让可见控件及展开的缩放面板,保留工具栏左侧空白区域。+ if (!this.toolbar.hidden && toolbarStyle.display !== "none" && toolbarStyle.visibility !== "hidden" &&+ Number(toolbarStyle.opacity) !== 0) {+ this.toolbar.querySelectorAll<HTMLElement>(".block__icon, .mindmap-view__zoom, .mindmap-view__zoom-actions")+ .forEach(control => {+ const bounds = control.getBoundingClientRect();+ const style = getComputedStyle(control);+ if (bounds.width && bounds.height && bounds.bottom > viewport.top && bounds.top < viewport.bottom &&+ rect.left + x < bounds.right && rect.right + x > bounds.left &&+ style.display !== "none" && style.visibility !== "hidden" && Number(style.opacity) !== 0) {+ top = Math.max(top, bounds.bottom + marginY);+ }+ });+ }let bottom = viewport.bottom - marginY;// 底部浮层按实际尺寸避让,横向定位后仍不相交的节点无需额外上移。[this.inspector, this.summaryControls].forEach(panel => {@@ -889,8 +905,8 @@ export class ListMindmapView {}});// 可用高度不足以完整显示节点时,优先保留节点顶部的正文。- const y = rect.top < viewport.top + marginY ? viewport.top + marginY - rect.top :- rect.bottom > bottom ? Math.max(viewport.top + marginY - rect.top, bottom - rect.bottom) : 0;+ const y = rect.top < top ? top - rect.top :+ rect.bottom > bottom ? Math.max(top - rect.top, bottom - rect.bottom) : 0;if (x || y) {const bounded = this.boundedPan(this.offsetX + x / scaleX, this.offsetY + y / scaleY);this.offsetX = bounded.x;diff --git a/app/src/protyle/render/listMindmap/viewportFocus.test.ts b/app/src/protyle/render/listMindmap/viewportFocus.test.tsindex ef7fa4007f..f7eebc01d3 100644--- a/app/src/protyle/render/listMindmap/viewportFocus.test.ts+++ b/app/src/protyle/render/listMindmap/viewportFocus.test.ts@@ -16,7 +16,8 @@ globalThis.View = View;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outpconst setup = () => {const frames: (() => void)[] = [];- const context: any = {clearTimeout, requestAnimationFrame: (action: () => void) => frames.push(action)};+ const context: any = {clearTimeout, requestAnimationFrame: (action: () => void) => frames.push(action),+ getComputedStyle: (element: any) => ({display: "block", visibility: "visible", opacity: "1", ...element.style})};runInNewContext(compiled, context);let focus = "editor";let finished = 0;@@ -25,6 +26,7 @@ const setup = () => {const target = Object.assign(new context.View(), {options: {host}, editingId: "new", model: {nodes: new Map([["new", {}]])},selectedId: "new", tooltip: {}, inspector: {hidden: true}, summaryControls: {hidden: true},+ toolbar: {hidden: false, querySelectorAll: (): unknown[] => []},nodeElements: new Map(), offsetX: 0, offsetY: 0,viewport: {contains: (element: unknown) => !!element, setPointerCapture: () => {},offsetWidth: 400, offsetHeight: 300,@@ -153,6 +155,69 @@ test("a node taller than the unobstructed area keeps its top visible", () => {assert.equal(100 + target.offsetY, 16);});+test("node focus clears visible toolbar controls with their actual heights after layout", () => {+ for (const bottom of [32, 60]) {+ const {target, frames, drawn} = setup();+ target.frame = 1;+ target.toolbar.querySelectorAll = () => [{getBoundingClientRect: () =>+ ({left: 280, top: 0, right: 400, bottom, width: 120, height: bottom})}];+ target.nodeElements.set("new", {getBoundingClientRect: () =>+ ({left: 300, top: 16, right: 380, bottom: 56, width: 80, height: 40})});+ target.focusNode("new");+ assert.equal(drawn(), 0);+ frames.forEach(action => action());+ assert.equal(16 + target.offsetY, bottom + 16);+ assert.equal(target.offsetX, 0);+ }+});++test("hidden toolbar controls and its empty horizontal area do not move a visible node", () => {+ const bounds = {left: 280, top: 0, right: 400, bottom: 48, width: 120, height: 48};+ for (const style of [{opacity: "0"}, {visibility: "hidden"}, {display: "none"}]) {+ for (const hiddenControl of [false, true]) {+ const {target, drawn} = setup();+ const control = {style: hiddenControl ? style : {}, getBoundingClientRect: () => bounds};+ target.toolbar.style = hiddenControl ? {} : style;+ target.toolbar.querySelectorAll = () => [control];+ target.nodeElements.set("new", {getBoundingClientRect: () =>+ ({left: 300, top: 16, right: 380, bottom: 56, width: 80, height: 40})});+ target.focusNode("new");+ assert.equal(drawn(), 0);+ }+ }+ const {target, drawn} = setup();+ target.toolbar.querySelectorAll = () => [{getBoundingClientRect: () => bounds}];+ target.nodeElements.set("new", {getBoundingClientRect: () =>+ ({left: 100, top: 16, right: 180, bottom: 56, width: 80, height: 40})});+ target.focusNode("new");+ assert.equal(drawn(), 0);+});++test("horizontal reveal and outer scaling also clear toolbar controls at the destination", () => {+ const {target} = setup();+ target.viewport.getBoundingClientRect = () =>+ ({left: 0, top: 0, right: 200, bottom: 150, width: 200, height: 150});+ target.toolbar.querySelectorAll = () => [{getBoundingClientRect: () =>+ ({left: 140, top: 0, right: 200, bottom: 24, width: 60, height: 24})}];+ target.nodeElements.set("new", {getBoundingClientRect: () =>+ ({left: 210, top: 8, right: 250, bottom: 28, width: 40, height: 20})});+ target.focusNode("new");+ assert.equal(target.offsetX, -116);+ assert.equal(target.offsetY, 48);+});++test("bottom clearance preserves the node top below the toolbar when the node is too tall", () => {+ const {target} = setup();+ target.toolbar.querySelectorAll = () => [{getBoundingClientRect: () =>+ ({left: 80, top: 0, right: 320, bottom: 48, width: 240, height: 48})}];+ target.inspector = {hidden: false, getBoundingClientRect: () =>+ ({left: 80, right: 320, top: 210, bottom: 292, width: 240, height: 82})};+ target.nodeElements.set("new", {getBoundingClientRect: () =>+ ({left: 100, top: 100, right: 180, bottom: 320, width: 80, height: 220})});+ target.focusNode("new");+ assert.equal(100 + target.offsetY, 64);+});+test("mouse, right-button and primary touch panning preserve the editing focus", () => {for (const overrides of [{}, {button: 2}, {pointerType: "touch"}]) {const {target, event, focus, finished} = setup();