Skip to content

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

:sparkles: Support right-button dragging to pan mind maps https://github.com/siyuan-note/siyuan/issues/18831

Vanessa37034b6fe157
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
index 142f80427b..22acaeaed1 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100950-9op5xi1.sy
@@ -7,7 +7,7 @@
"id": "20200924100950-9op5xi1",
"title": "Shortcuts",
"type": "doc",
- "updated": "20260921111101"
+ "updated": "20260921221035"
},
"Children": [
{
@@ -12301,7 +12301,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-4zeuyl4",
- "updated": "20260921111101"
+ "updated": "20260921221035"
},
"HeadingLevel": 3,
"Children": [
@@ -12316,7 +12316,7 @@
"Type": "NodeTable",
"Properties": {
"id": "20260921105011-3srqnh0",
- "updated": "20260921111101",
+ "updated": "20260921221035",
"colgroup": "|"
},
"TableAligns": [
@@ -12679,6 +12679,32 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Pan the canvas"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "Hold the right mouse button and drag"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
index 584e49d129..987f79f86d 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200813004551-gm0pbn1.sy
@@ -7,7 +7,7 @@
"id": "20200813004551-gm0pbn1",
"title": "快捷键",
"type": "doc",
- "updated": "20260921191955"
+ "updated": "20260921221035"
},
"Children": [
{
@@ -12287,7 +12287,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-hmrchvc",
- "updated": "20260921191955"
+ "updated": "20260921221035"
},
"HeadingLevel": 3,
"Children": [
@@ -12302,7 +12302,7 @@
"Type": "NodeTable",
"Properties": {
"id": "20260921105011-fr0uxw6",
- "updated": "20260921111101",
+ "updated": "20260921221035",
"colgroup": "|"
},
"TableAligns": [
@@ -12753,6 +12753,32 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "移动画布"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "按住鼠标右键拖动"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
index bfd650aa0a..1512963753 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226122549-jktxego.sy
@@ -7,7 +7,7 @@
"id": "20211226122549-jktxego",
"title": "快捷鍵",
"type": "doc",
- "updated": "20260921111101"
+ "updated": "20260921221035"
},
"Children": [
{
@@ -12293,7 +12293,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-z0oyw36",
- "updated": "20260921111101"
+ "updated": "20260921221035"
},
"HeadingLevel": 3,
"Children": [
@@ -12308,7 +12308,7 @@
"Type": "NodeTable",
"Properties": {
"id": "20260921105011-f8y6pxv",
- "updated": "20260921111101",
+ "updated": "20260921221035",
"colgroup": "|"
},
"TableAligns": [
@@ -12671,6 +12671,32 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "移動畫布"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "按住滑鼠右鍵拖曳"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
index 281018898b..2a4e3d72b2 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-xsbxokr.sy
@@ -9,7 +9,7 @@
"id": "20240530101000-xsbxokr",
"title": "ショートカット",
"type": "doc",
- "updated": "20260921111101"
+ "updated": "20260921221035"
},
"Children": [
{
@@ -12251,7 +12251,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-icqlkb6",
- "updated": "20260921111101"
+ "updated": "20260921221035"
},
"HeadingLevel": 3,
"Children": [
@@ -12266,7 +12266,7 @@
"Type": "NodeTable",
"Properties": {
"id": "20260921105011-01k7syf",
- "updated": "20260921111101",
+ "updated": "20260921221035",
"colgroup": "|"
},
"TableAligns": [
@@ -12629,6 +12629,32 @@
]
}
]
+ },
+ {
+ "Type": "NodeTableRow",
+ "Data": "tr",
+ "Children": [
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "キャンバスを移動"
+ }
+ ]
+ },
+ {
+ "Type": "NodeTableCell",
+ "Data": "td",
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "マウスの右ボタンを押しながらドラッグ"
+ }
+ ]
+ }
+ ]
}
]
},
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 23535ed3d6..e407463f72 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -596,8 +596,8 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
compactNode.style.height = "";
view.refreshLayout();
await settle();
- const sendPointer = (element: Element, type: string, x: number, y: number) => element.dispatchEvent(new PointerEvent(type, {
- bubbles: true, cancelable: true, pointerId: 1, pointerType: "mouse", button: 0, clientX: x, clientY: y,
+ const sendPointer = (element: Element, type: string, x: number, y: number, button = 0) => element.dispatchEvent(new PointerEvent(type, {
+ bubbles: true, cancelable: true, pointerId: 1, pointerType: "mouse", button, clientX: x, clientY: y,
}));
const sourceRect = nodeElement(alpha).getBoundingClientRect();
const targetRect = nodeElement(beta).getBoundingClientRect();
@@ -609,6 +609,20 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
sendPointer(viewport, "pointerup", sourcePoint.x, sourcePoint.y);
check.equal(edits.length, 0);
check.equal(moves.length, 0);
+ const panOrigin = {x: view.offsetX, y: view.offsetY};
+ sendPointer(nodeElement(alpha), "pointerdown", sourcePoint.x, sourcePoint.y, 2);
+ sendPointer(viewport, "pointermove", sourcePoint.x + 30, sourcePoint.y + 20, 2);
+ check.equal(view.offsetX, panOrigin.x + 30, "right drag pans over nodes");
+ check.equal(view.offsetY, panOrigin.y + 20, "right drag pans vertically");
+ check.equal(host.querySelector(".list-mindmap__ghost"), null);
+ sendPointer(viewport, "pointerup", sourcePoint.x + 30, sourcePoint.y + 20, 2);
+ const contextMenu = new MouseEvent("contextmenu", {bubbles: true, cancelable: true});
+ viewport.dispatchEvent(contextMenu);
+ check.equal(contextMenu.defaultPrevented, true, "right pan suppresses the native menu");
+ check.equal(moves.length, 0, "right pan does not move nodes");
+ view.offsetX = panOrigin.x;
+ view.offsetY = panOrigin.y;
+ view.draw();
sendPointer(nodeElement(alpha), "pointerdown", sourcePoint.x, sourcePoint.y);
sendPointer(viewport, "pointermove", targetPoint.x, targetPoint.y);
check.ok(host.querySelector(".list-mindmap__ghost"));
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index be0bfd3e13..441e0d3f4e 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -53,6 +53,7 @@ export interface ListMindmapViewOptions {
interface PointerState {
pointerId: number;
+ rightButton?: boolean;
id?: string;
startX: number;
startY: number;
@@ -82,6 +83,7 @@ const createElement = <T extends keyof HTMLElementTagNameMap>(tag: T, className:
};
export class ListMindmapView {
+ private suppressPanContextMenu = false;
private readonly options: ListMindmapViewOptions;
private model: ListMindmapModel;
private readonly viewport: HTMLDivElement;
@@ -175,6 +177,11 @@ export class ListMindmapView {
this.listen(this.viewport, "pointermove", this.pointerMove);
this.listen(this.viewport, "pointerleave", () => this.setHoveredLine());
this.listen(this.viewport, "pointerup", this.pointerUp);
+ this.listen(this.viewport, "contextmenu", (event: MouseEvent) => {
+ if (this.suppressPanContextMenu) {
+ event.preventDefault();
+ }
+ });
this.listen(this.viewport, "pointercancel", this.cancelPointer);
this.listen(this.viewport, "lostpointercapture", this.cancelPointer);
this.listen(window, "pointerup", (event: PointerEvent) => {
@@ -1269,10 +1276,12 @@ export class ListMindmapView {
private pointerDown = (event: PointerEvent) => {
clearTimeout(this.linkTimer);
this.suppressLinkClick = false;
+ this.suppressPanContextMenu = false;
const target = event.target as HTMLElement;
- if (event.button !== 0 || target.closest("button, input, select, textarea, audio, video, iframe, .list-mindmap__node--editing")) {
+ if (![0, 2].includes(event.button) || target.closest("button, input, select, textarea, audio, video, iframe, .list-mindmap__node--editing")) {
return;
}
+ this.suppressPanContextMenu = event.button === 2;
const element = target.closest<HTMLElement>(".list-mindmap__node");
const id = element?.dataset.mindmapId;
this.pendingPointerId = event.pointerId;
@@ -1284,11 +1293,11 @@ export class ListMindmapView {
};
private beginPointer(event: PointerEvent, id?: string) {
- if (this.panning) {
+ if (this.panning || event.button === 2) {
id = undefined;
event.preventDefault();
}
- if (!this.panning && !id && !this.options.readOnly && !this.relationFrom) {
+ if (event.button !== 2 && !this.panning && !id && !this.options.readOnly && !this.relationFrom) {
const line = this.findLine(event);
const points = line?.relation && this.relationRoutes.get(line.id);
if (points) {
@@ -1324,6 +1333,7 @@ export class ListMindmapView {
this.options.host.focus({preventScroll: true});
this.pointer = {
pointerId: event.pointerId,
+ rightButton: event.button === 2,
id: !this.options.readOnly && id && !this.model.nodes.get(id)?.virtual ? id : undefined,
startX: event.clientX,
startY: event.clientY,
@@ -1341,7 +1351,7 @@ export class ListMindmapView {
}
private pointerMove = (event: PointerEvent) => {
- if (this.relationFrom) {
+ if (this.relationFrom && !this.pointer?.rightButton) {
const bounds = this.viewport.getBoundingClientRect();
const id = (event.target as Element).closest<HTMLElement>(".list-mindmap__node")?.dataset.mindmapId;
this.relationPreview = {
@@ -1489,7 +1499,7 @@ export class ListMindmapView {
this.cancelPointer();
if (moved && id && targetId && placement) {
this.options.onMove?.(id, targetId, placement);
- } else if (!moved && !id && !this.options.readOnly && !this.panning) {
+ } else if (!moved && !id && !pointer.rightButton && !this.options.readOnly && !this.panning) {
this.selectLine(event);
}
};