Skip to content

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

:bug: Align pinned document menu positioning with the document tree https://github.com/siyuan-note/siyuan/issues/19269

Danielb84aa2dccb78
diff --git a/app/src/layout/dock/PinnedDocs.test.ts b/app/src/layout/dock/PinnedDocs.test.ts
index 1d06831ea5..ff128da42f 100644
--- a/app/src/layout/dock/PinnedDocs.test.ts
+++ b/app/src/layout/dock/PinnedDocs.test.ts
@@ -23,7 +23,7 @@ interface IPanelHarness {
loadChildren(row: unknown, children: unknown, generation: number): Promise<void>;
drop(ids: string[], x: number, y: number, allowSource?: boolean): Promise<void>;
click(event: unknown): void;
- menu(row: unknown, x: number, y: number): void;
+ menu(row: unknown, position: {x: number, y: number, h: number}): void;
toggle(row: unknown): void;
open(id: string, notebook: string): void;
mobile?: boolean;
@@ -130,15 +130,17 @@ test("collapse clears descendant expansion and persists the closed section", asy
test("pinned document more actions open the source document menu", () => {
const {panel, calls} = loadPanel();
const row = {dataset: {nodeId: "document", notebook: "notebook", path: "/document.sy"}};
+ const button = {getBoundingClientRect: () => ({left: 180, bottom: 120, height: 24})};
panel.click({
stopPropagation: () => {}, clientX: 10, clientY: 20,
- target: {closest: (selector: string) => selector === "[data-pin-row]" || selector === "[data-pin-more]" ? row : null},
+ target: {closest: (selector: string) => selector === "[data-pin-row]" ? row : selector === "[data-pin-more]" ? button : null},
});
assert.equal(calls[0].kind, "menu");
assert.deepEqual(calls[0].args.slice(1), ["notebook", "/document.sy", row]);
assert.equal(calls[1].kind, "popup");
+ assert.deepEqual({...calls[1].args[0] as object}, {x: 180, y: 120, h: 24});
panel.mobile = true;
- panel.menu(row, 10, 20);
+ panel.menu(row, {x: 180, y: 120, h: 24});
assert.equal(calls[3].kind, "fullscreen");
});
@@ -159,7 +161,8 @@ test("pinned roots share one list and retain each document notebook without wrap
test("touch long press suppresses the context menu before and during dragging", () => {
const {panel, calls} = loadPanel();
- const row = {dataset: {nodeId: "document", notebook: "notebook", path: "/document.sy"}};
+ const row = {dataset: {nodeId: "document", notebook: "notebook", path: "/document.sy"},
+ getBoundingClientRect: () => ({left: 0, bottom: 120, height: 28})};
let prevented = 0;
const event = {stopPropagation: () => {}, preventDefault: () => prevented++,
target: {closest: () => row}, clientX: 10, clientY: 20};
@@ -175,6 +178,9 @@ test("touch long press suppresses the context menu before and during dragging",
panel.suppressClick = false;
panel.contextMenu(event);
assert.equal(calls[0].kind, "menu");
+ assert.deepEqual({...calls[1].args[0] as object}, {x: 10, y: 120, h: 28});
+ panel.contextMenu({...event, clientX: 200, clientY: 115});
+ assert.deepEqual({...calls[3].args[0] as object}, {x: 200, y: 120, h: 28});
});
test("mobile pinned rows use touch dragging without native HTML dragging", async () => {
diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.ts
index 302dd02655..762579c09b 100644
--- a/app/src/layout/dock/PinnedDocs.ts
+++ b/app/src/layout/dock/PinnedDocs.ts
@@ -419,8 +419,10 @@ export class PinnedDocs {
row.classList.toggle("b3-list-item--focus");
return;
}
- if (target.closest("[data-pin-more]")) {
- this.menu(row, event.clientX, event.clientY);
+ const moreButton = target.closest("[data-pin-more]");
+ if (moreButton) {
+ const rect = moreButton.getBoundingClientRect();
+ this.menu(row, {x: rect.left, y: rect.bottom, h: rect.height});
} else if (target.closest("[data-pin-new]")) {
newFileInTree(this.app, row.dataset.notebook, row.dataset.path);
} else if (target.closest("[data-pin-toggle]")) {
@@ -445,7 +447,7 @@ export class PinnedDocs {
}
}
- private menu(row: HTMLElement, x: number, y: number) {
+ private menu(row: HTMLElement, position: IPosition) {
if (row.dataset.unavailable === "true") {
const menu = window.siyuan.menus.menu;
menu.remove();
@@ -458,12 +460,12 @@ export class PinnedDocs {
icon: "iconUnpin",
click: () => { updatePinnedDocs([row.dataset.nodeId], "unpin"); },
}).element);
- if (this.mobile) { menu.fullscreen("bottom"); } else { menu.popup({x, y}); }
+ if (this.mobile) { menu.fullscreen("bottom"); } else { menu.popup(position); }
}
return;
}
const menu = initFileMenu(this.app, row.dataset.notebook, row.dataset.path, row);
- if (this.mobile) { menu.fullscreen("bottom"); } else { menu.popup({x, y}); }
+ if (this.mobile) { menu.fullscreen("bottom"); } else { menu.popup(position); }
}
private setDragImage(row: HTMLElement, dataTransfer: DataTransfer) {
@@ -554,7 +556,8 @@ export class PinnedDocs {
event.preventDefault();
// 触摸长按由拖拽处理,避免弹出菜单中断手势。
if (this.touch || this.suppressClick) { return; }
- this.menu(row, event.clientX, event.clientY);
+ const rect = row.getBoundingClientRect();
+ this.menu(row, {x: event.clientX, y: rect.bottom, h: rect.height});
}
}