Skip to content

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

:sparkles: Improve mind map touch dragging and pan tool access https://github.com/siyuan-note/siyuan/issues/20723

Danielb2c978002fd0
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 3b5bfe0d46..da2a776f6f 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": "20261020162345"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -4365,7 +4365,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210106154056-koo4wdj",
- "updated": "20261018200107"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -13115,7 +13115,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-4zeuyl4",
- "updated": "20261020162345"
+ "updated": "20261020181700"
},
"HeadingLevel": 3,
"Children": [
@@ -13143,12 +13143,30 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261018200107-p7ncdxc",
- "updated": "20261018200107"
+ "updated": "20261020181700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "Hold Ctrl (Command on macOS) and drag the canvas with the right mouse button to pan temporarily without changing keyboard focus or activating a reading canvas. Ordinary wheel input then continues scrolling the document. This gesture is unavailable while the view is locked. Ordinary left dragging on blank canvas does not pan; the Hand Tool allows left-button panning."
+ "Data": "Hold Ctrl (Command on macOS) and drag the canvas with the right mouse button to pan temporarily without changing keyboard focus or activating a reading canvas. Ordinary wheel input then continues scrolling the document. This gesture is unavailable while the view is locked. Ordinary left dragging on blank canvas selects nodes with a box. For left-button panning, enable "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "More"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "Hand Tool"
+ },
+ {
+ "Type": "NodeText",
+ "Data": ". While enabled, the toolbar shows a button for leaving this mode directly. On a touchscreen, tap the map to activate the canvas. A quick one-finger drag starting on a node or blank canvas pans the view; to move a node, hold it until the outline appears, then drag. Before activation, one-finger swipes still scroll the document. Two-finger zooming and panning, double-tap editing, and the selection, summary and connection modes keep their existing interactions."
}
]
},
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 7223b9e630..91137e23fb 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": "20261020162345"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -4363,7 +4363,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20201227133317-rkh4bji",
- "updated": "20261018200107"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -13097,7 +13097,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-hmrchvc",
- "updated": "20261020162345"
+ "updated": "20261020181700"
},
"HeadingLevel": 3,
"Children": [
@@ -13125,12 +13125,30 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261018200107-yv270lj",
- "updated": "20261018200107"
+ "updated": "20261020181700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "按住 Ctrl(macOS 为 Command)并用鼠标右键拖动画布可临时平移,不会改变键盘焦点或激活阅读中的画布,之后普通滚轮仍滚动文档。视图锁定时此手势不可用。普通模式下空白区域的左键拖动不会平移画布;启用手形工具后可用左键拖动平移。"
+ "Data": "按住 Ctrl(macOS 为 Command)并用鼠标右键拖动画布可临时平移,不会改变键盘焦点或激活阅读中的画布,之后普通滚轮仍滚动文档。视图锁定时此手势不可用。普通模式下,空白区域的鼠标左键拖动用于框选节点。需要左键平移时,可在 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "更多"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "手形工具"
+ },
+ {
+ "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 20912656a6..ceed3385f1 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": "20261020162345"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -4357,7 +4357,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122652-htptsmh",
- "updated": "20261018200107"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -13103,7 +13103,7 @@
"Type": "NodeHeading",
"Properties": {
"id": "20260921105011-z0oyw36",
- "updated": "20261020162345"
+ "updated": "20261020181700"
},
"HeadingLevel": 3,
"Children": [
@@ -13131,12 +13131,30 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261018200107-s3tp7x9",
- "updated": "20261018200107"
+ "updated": "20261020181700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "按住 Ctrl(macOS 為 Command)並用滑鼠右鍵拖曳畫布可暫時平移,不會改變鍵盤焦點或啟用閱讀中的畫布,之後一般滾輪仍捲動文件。檢視鎖定時此手勢無法使用。一般模式下空白區域的左鍵拖曳不會平移畫布;啟用手形工具後可用左鍵拖曳平移。"
+ "Data": "按住 Ctrl(macOS 為 Command)並用滑鼠右鍵拖曳畫布可暫時平移,不會改變鍵盤焦點或啟用閱讀中的畫布,之後一般滾輪仍捲動文件。檢視鎖定時此手勢無法使用。一般模式下,空白區域的滑鼠左鍵拖曳用於框選節點。需要左鍵平移時,可在 "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "更多"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "手形工具"
+ },
+ {
+ "Type": "NodeText",
+ "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.sy
index 2e70c47dfd..78033c16cf 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": "20261020165811"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -2090,7 +2090,7 @@
"Properties": {
"ID": "20240530101000-ch5e4vh",
"id": "20240530101000-1ev7xub",
- "updated": "20261020165811"
+ "updated": "20261020181700"
},
"Children": [
{
@@ -2129,12 +2129,30 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261018163000-bic9sbi",
- "updated": "20261019201307"
+ "updated": "20261020181700"
},
"Children": [
{
"Type": "NodeText",
- "Data": "マインドマップ上のマウスホイールと 1 本指のスワイプは、初期状態では文書をスクロールします。デスクトップではマップをクリック、モバイルではマップを 1 回タップするとキャンバスを操作できます。モバイルではツールバーの「手のひらツール」でも 1 本指の移動を行い、ツールをオフにするとノードを選択・ドラッグ・編集できます。閲覧中でもノードをダブルタップすると編集できます。操作中は枠が強調表示され、ホイールまたはマウスの右ボタンを押したドラッグでキャンバスを移動します。手のひらツールでは左ボタンでのドラッグも使えます。通常モードでは空白部分を左ボタンでドラッグしてもキャンバスは移動しません。タッチ画面では操作中に 1 本指でキャンバスを移動できます。移動範囲の端でも文書はスクロールしません。マップの外をクリックする、キーボードフォーカスを外に移す、またはキャンバス上で Esc を押すと閲覧に戻ります。全画面表示ではキャンバス操作を維持し、全画面表示を終了すると閲覧に戻ります。"
+ "Data": "マインドマップ上のマウスホイールと 1 本指のスワイプは、初期状態では文書をスクロールします。デスクトップではマップをクリック、タッチ画面ではマップを 1 回タップするとキャンバスを操作できます。操作中は枠が強調表示され、ホイールまたはマウスの右ボタンを押したドラッグでキャンバスを移動します。タッチ画面では、ノード上でも空白部分でも、すばやく 1 本指でドラッグするとキャンバスが移動します。ノードを移動するには、ノードを長押しして枠の表示を確認してからドラッグします。閲覧中でもノードをダブルタップすると編集できます。2 本指での拡大・縮小と移動、複数選択、要約、関連線の操作は従来どおりです。通常モードで空白部分をマウスの左ボタンでドラッグすると、ノードを範囲選択できます。左ボタンでキャンバスを移動するには、"
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "詳細"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " - "
+ },
+ {
+ "Type": "NodeTextMark",
+ "TextMarkType": "kbd",
+ "TextMarkTextContent": "手のひらツール"
+ },
+ {
+ "Type": "NodeText",
+ "Data": " を有効にします。有効な間は、ツールバーに直接解除できるボタンが表示されます。移動範囲の端でも文書はスクロールしません。マップの外をクリックする、キーボードフォーカスを外に移す、またはキャンバス上で Esc を押すと閲覧に戻ります。全画面表示ではキャンバス操作を維持し、全画面表示を終了すると閲覧に戻ります。"
}
]
},
diff --git a/app/src/assets/scss/protyle/_mindmap-view.scss b/app/src/assets/scss/protyle/_mindmap-view.scss
index 69102b17ac..2a2396fd0c 100644
--- a/app/src/assets/scss/protyle/_mindmap-view.scss
+++ b/app/src/assets/scss/protyle/_mindmap-view.scss
@@ -391,6 +391,11 @@
box-shadow: inset 0 0 0 2px var(--b3-theme-primary);
}
+ &--drag-ready {
+ outline: 2px solid var(--b3-theme-primary);
+ outline-offset: 2px;
+ }
+
&--dragging {
opacity: .35;
cursor: grabbing;
diff --git a/app/src/protyle/render/listMindmap/anchorsView.test.ts b/app/src/protyle/render/listMindmap/anchorsView.test.ts
index e0977749ea..9120c20756 100644
--- a/app/src/protyle/render/listMindmap/anchorsView.test.ts
+++ b/app/src/protyle/render/listMindmap/anchorsView.test.ts
@@ -21,7 +21,7 @@ globalThis.View = View;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outp
const setup = (overrides: Partial<ListMindmapRelation> = {}) => {
const relation: ListMindmapRelation = {id: "r", from: "a", to: "b", label: "Keep", arrowDirection: "reverse", ...overrides};
const changes: {id: string, patch: Partial<ListMindmapRelation>, expected: string}[] = [];
- const sandbox: any = {...routing, cancelAnimationFrame: () => {}, requestAnimationFrame: () => 1};
+ const sandbox: any = {...routing, clearTimeout, cancelAnimationFrame: () => {}, requestAnimationFrame: () => 1};
runInNewContext(compiled, sandbox);
const view = new sandbox.View();
const positions = new Map([
diff --git a/app/src/protyle/render/listMindmap/arrows.test.ts b/app/src/protyle/render/listMindmap/arrows.test.ts
index 60d05ca3a8..4634d2daaa 100644
--- a/app/src/protyle/render/listMindmap/arrows.test.ts
+++ b/app/src/protyle/render/listMindmap/arrows.test.ts
@@ -11,8 +11,8 @@ const source = createSourceFile("view.ts", readFileSync("src/protyle/render/list
ScriptTarget.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", "drawSummaryPreview", "findLine", "renderInspector"].includes(item.name?.getText(source)));
+assert.equal(methods.length, 5);
const compiled = transpileModule(`class View {
${methods.map(item => item.getText(source)).join("\n")}
}
diff --git a/app/src/protyle/render/listMindmap/connectorMenu.test.ts b/app/src/protyle/render/listMindmap/connectorMenu.test.ts
index fb969b6e59..f08ad90d52 100644
--- a/app/src/protyle/render/listMindmap/connectorMenu.test.ts
+++ b/app/src/protyle/render/listMindmap/connectorMenu.test.ts
@@ -37,6 +37,8 @@ test("desktop and mobile connector menus persist one undoable change and preserv
let item: IMenu;
let defaultItem: IMenu;
let expandItem: IMenu;
+ let panItem: IMenu;
+ let entries: IMenu[];
let defaultStyle = "bezier";
const defaults: string[] = [];
const placements: unknown[] = [];
@@ -63,9 +65,12 @@ test("desktop and mobile connector menus persist one undoable change and preserv
build(undefined, {show: (open: () => void) => open()});
},
Menu: class {
+ constructor() { entries = []; }
addItem(value: IMenu) {
+ entries.push(value);
if (value.id === "defaultConnectorStyle") { defaultItem = value; }
else if (value.id === "expandLevel") { expandItem = value; }
+ else if (value.id === "pan") { panItem = value; }
else { item = value; }
}
open(position: unknown) { placements.push(position); }
@@ -123,5 +128,12 @@ test("desktop and mobile connector menus persist one undoable change and preserv
(defaultItem.submenu as IMenu[]).find(entry => entry.id === "spline").click(undefined, undefined);
assert.deepEqual(defaults, ["rounded"], "a stale menu cannot change preferences after editing is disabled");
assert.equal(transactions.length, count, "an already open menu cannot edit a newly read-only map");
+ let panToggles = 0;
+ target.onSettingsMenu(anchor, undefined, {active: true, toggle: () => panToggles++});
+ assert.deepEqual(entries.map(entry => entry.id), ["pan"], "read-only menus contain no editable global settings");
+ assert.equal(panItem.checked, true, "the fallback pan mode remains visible in a read-only map's More menu");
+ panItem.click(undefined, undefined);
+ assert.equal(panToggles, 1);
+ assert.equal(transactions.length, count, "switching pan mode never changes source data");
}
});
diff --git a/app/src/protyle/render/listMindmap/index.ts b/app/src/protyle/render/listMindmap/index.ts
index 3cc5edd806..e9b8bba935 100644
--- a/app/src/protyle/render/listMindmap/index.ts
+++ b/app/src/protyle/render/listMindmap/index.ts
@@ -249,32 +249,37 @@ class ListMindmapController {
onLockChange: locked => canEdit(owner, list) ? this.metadata(metadata => {
metadata.viewLocked = locked;
}) : Promise.resolve(true),
- onSettingsMenu: (anchor, expand) => {
+ onSettingsMenu: (anchor, expand, pan) => {
toggleMenu({
target: anchor,
build: (_menu, session) => {
- if (!canEdit(owner, list)) {
- return;
- }
const menu = new Menu();
- menu.addItem(getListMindmapConnectorMenuItem(readListMindmap(list).metadata.connectorStyle || "bezier",
- style => {
- void this.metadata(metadata => {
- if ((metadata.connectorStyle || "bezier") === style) {
- return false;
- }
- if (style === "bezier") {
- delete metadata.connectorStyle;
- } else {
- metadata.connectorStyle = style;
- }
- });
- }, window.siyuan.languages));
- menu.addItem(getListMindmapConnectorMenuItem(getDefaultListMindmapConnectorStyle(), style => {
- if (canEdit(owner, list)) {
- setDefaultListMindmapConnectorStyle(style);
- }
- }, window.siyuan.languages, "default"));
+ if (pan) {
+ menu.addItem({
+ id: "pan", icon: "iconPan", label: window.siyuan.languages.cursorHand,
+ checked: pan.active, click: pan.toggle,
+ });
+ }
+ if (canEdit(owner, list)) {
+ menu.addItem(getListMindmapConnectorMenuItem(readListMindmap(list).metadata.connectorStyle || "bezier",
+ style => {
+ void this.metadata(metadata => {
+ if ((metadata.connectorStyle || "bezier") === style) {
+ return false;
+ }
+ if (style === "bezier") {
+ delete metadata.connectorStyle;
+ } else {
+ metadata.connectorStyle = style;
+ }
+ });
+ }, window.siyuan.languages));
+ menu.addItem(getListMindmapConnectorMenuItem(getDefaultListMindmapConnectorStyle(), style => {
+ if (canEdit(owner, list)) {
+ setDefaultListMindmapConnectorStyle(style);
+ }
+ }, window.siyuan.languages, "default"));
+ }
if (expand) {
menu.addItem({
id: "expandLevel", icon: "iconExpandLevel", label: window.siyuan.languages.expandLevel,
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index 3d0a668f15..098d47de67 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -308,7 +308,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
formula.innerHTML = '<span class="katex">rendered formula</span>';
formula.setAttribute("data-render", "true");
});
- }, {TIMEOUT_DBLCLICK: 190, CUSTOM_SY_LIST_MINDMAP: "custom-sy-list-mindmap",
+ }, {TIMEOUT_DBLCLICK: 190, TIMEOUT_LONGPRESS: 460, CUSTOM_SY_LIST_MINDMAP: "custom-sy-list-mindmap",
CUSTOM_SY_LIST_MINDMAP_DATA: "custom-sy-list-mindmap-data", CUSTOM_SY_MINDMAP_CODE: "custom-sy-mindmap-code",
CUSTOM_SY_CODE_TAB_SPACES: "custom-sy-code-tab-spaces"}, () => {});
const lute = Lute.New();
@@ -1162,6 +1162,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
let redo = 0;
let settingsOpened = 0;
let overflowExpand: ((level: number | "expandAll" | "foldAll") => void) | undefined;
+ let panMenu: {active: boolean, toggle: () => void};
let finishAllowed: boolean | Promise<boolean> = true;
const options = {
host, model,
@@ -1189,9 +1190,10 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
onFold: (id: string) => folds.push(id),
onUndo: () => undo++,
onRedo: () => redo++,
- onSettingsMenu: (_anchor: HTMLElement, expand?: typeof overflowExpand) => {
+ onSettingsMenu: (_anchor: HTMLElement, expand?: typeof overflowExpand, pan?: typeof panMenu) => {
settingsOpened++;
overflowExpand = expand;
+ panMenu = pan;
},
onNodeStyle: (...args: unknown[]) => nodeStyles.push(args),
onRelationAdd: (...args: unknown[]) => relationAdditions.push(args),
@@ -1201,6 +1203,12 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
};
const frame = () => new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
const settle = async () => { await frame(); await frame(); };
+ const enableHand = (targetHost: HTMLElement) => {
+ targetHost.querySelector<HTMLButtonElement>('[aria-label="more"]').click();
+ check.ok(panMenu);
+ check.equal(panMenu.active, false);
+ panMenu.toggle();
+ };
// 方向键选中视口外的节点时自动平移,待完成的布局和只读视图使用同一定位逻辑。
const navigationHost = document.createElement("div");
@@ -1313,7 +1321,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
// 顶部控件按悬停、焦点和全屏的实际可见状态避让,缩放画布保持相同的局部间距。
const navigationToolbar = navigationHost.querySelector<HTMLElement>(".mindmap-view__toolbar");
const navigationFit = () => navigationToolbar.querySelector<HTMLButtonElement>('[aria-label="listMindmapFit"]');
- const navigationControl = () => navigationToolbar.querySelector<HTMLButtonElement>('[aria-label="cursorHand"]');
+ const navigationControl = () => navigationToolbar.querySelector<HTMLButtonElement>('[aria-label="more"]');
const moveNavigationPointer = async (inside: boolean) => {
navigationHost.scrollIntoView({block: "start"});
const bounds = navigationHost.getBoundingClientRect();
@@ -1599,7 +1607,8 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(view.findLine(branch).id, child.id, "the real canvas hit test selects each horizontal branch");
}
view.setReadOnly(true);
- check.equal(host.querySelector('[aria-label="more"]'), null, "read-only views render saved styles without an edit menu");
+ check.ok(host.querySelector('[aria-label="more"]'), "read-only views retain the fallback pan menu");
+ check.equal(host.querySelector('[aria-label="connect"]'), null, "read-only views do not expose object editing actions");
check.equal(view.linePaths.filter((line: {relation: boolean}) => !line.relation).length, view.edges.length);
view.setReadOnly(false);
}
@@ -2040,7 +2049,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
}
const firstButton = toolbar.querySelector("button").getBoundingClientRect();
const lastButton = toolbarGroup.lastElementChild.getBoundingClientRect();
- check.equal(lastButton.top > firstButton.top, width < 240,
+ check.equal(lastButton.top > firstButton.top, width < 180,
`compact global toolbars wrap only when necessary, width=${width}, fontSize=${fontSize}`);
check.equal(getComputedStyle(toolbarPopup).display, "flex", "zoom popup remains visible");
if (width >= 240) {
@@ -2057,14 +2066,14 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
if (width === 180) {
const popupBounds = toolbarPopup.getBoundingClientRect();
check.ok(popupBounds.bottom > toolbar.getBoundingClientRect().bottom,
- "zoom popup extends below the wrapping toolbar");
+ "zoom popup extends below the compact toolbar");
const slider = toolbarPopup.querySelector<HTMLInputElement>("input");
const sliderBounds = slider.getBoundingClientRect();
check.equal(document.elementFromPoint(sliderBounds.left + sliderBounds.width / 2,
sliderBounds.top + sliderBounds.height / 2), slider, "zoom slider is not clipped or covered");
slider.value = "125";
slider.dispatchEvent(new Event("input", {bubbles: true}));
- check.equal(view.scale, 1.25, "zoom controls remain usable after wrapping");
+ check.equal(view.scale, 1.25, "zoom controls remain usable at narrow widths");
}
}
}
@@ -3208,7 +3217,9 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(getComputedStyle(panViewport).cursor, "default");
check.equal(getComputedStyle(host.querySelector(".mindmap-view__node")).cursor, "default");
check.equal(panButton.querySelector("use").getAttribute("xlink:href"), "#iconPan");
- panButton.click();
+ check.equal(panButton.hidden, true, "the inactive hand tool is available through More without taking toolbar space");
+ enableHand(host);
+ check.equal(panButton.hidden, false, "the active mode provides a direct exit button");
check.equal(panButton.getAttribute("aria-pressed"), "true");
check.equal(getComputedStyle(panViewport).cursor, "grab");
const panNode = host.querySelector<HTMLElement>(".mindmap-view__node");
@@ -3224,6 +3235,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(host.querySelector(".mindmap-view__ghost"), null);
panButton.click();
check.equal(panButton.getAttribute("aria-pressed"), "false");
+ check.equal(panButton.hidden, true);
check.equal(getComputedStyle(panViewport).cursor, "default");
check.ok(getComputedStyle(panNode).pointerEvents !== "none");
single.zoomAt(2.5);
@@ -3467,7 +3479,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.ok(Array.from(panHost.querySelectorAll(".mindmap-view__toolbar use"))
.every(icon => icon.getAttribute("xlink:href") !== "#iconEdit"), "canvas activation has no separate pencil button");
const hand = panHost.querySelector<HTMLButtonElement>('[aria-label="cursorHand"]');
- hand.click();
+ enableHand(panHost);
check.equal(panView.interactionActive, true);
check.equal(getComputedStyle(viewport).touchAction, "none");
check.equal(hand.getAttribute("aria-pressed"), "true", "hand tool activates one-finger canvas panning");
@@ -3506,7 +3518,7 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
check.equal(panView.interactionActive, true, "desktop pointer input activates the canvas");
document.body.dispatchEvent(new PointerEvent("pointerdown", {bubbles: true}));
check.equal(panView.interactionActive, false, "outside pointer input returns to reading");
- hand.click();
+ enableHand(panHost);
panHost.dispatchEvent(new FocusEvent("focusout", {relatedTarget: followingContent}));
check.equal(panView.interactionActive, false, "moving focus outside returns to reading");
panView.offsetX = 16 - rootPosition.x * panView.scale;
@@ -3571,6 +3583,85 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
scrollHost.remove();
}
+ // 密集节点上的快速触屏拖动平移画布,长按确认后才移动节点。
+ {
+ const touchSource = document.createElement("div");
+ touchSource.innerHTML = lute.Md2BlockDOM("* Root\n * First\n * Second\n * Third\n");
+ const touchModel = api.readListMindmap(touchSource.firstElementChild as HTMLElement);
+ const touchHost = document.createElement("div");
+ touchHost.style.cssText = "position:fixed;left:0;top:0;width:600px;height:400px;z-index:100";
+ document.body.append(touchHost);
+ const touchMoves: unknown[][] = [];
+ const touchView = new api.ListMindmapView({...options, host: touchHost, model: touchModel,
+ onMove: (...args: unknown[]) => touchMoves.push(args)});
+ await settle();
+ const originalHTML = touchModel.list.outerHTML;
+ const firstId = touchModel.root.children[0].id;
+ const lastId = touchModel.root.children[2].id;
+ const touchNode = () => touchHost.querySelector<HTMLElement>(`[data-mindmap-id="${firstId}"]`);
+ const point = (id: string) => {
+ const rect = touchHost.querySelector<HTMLElement>(`[data-mindmap-id="${id}"]`).getBoundingClientRect();
+ return {id: 1, x: Math.round(rect.left + rect.width / 2), y: Math.round(rect.top + rect.height / 2)};
+ };
+ const nativeTouch = (events: Record<string, unknown>[]) =>
+ require("electron").ipcRenderer.invoke("mindmap-view-native-touch", events);
+ touchView.setInteractionActive(true);
+ const initialSelection = touchView.getSelectedId();
+ const from = point(firstId);
+ const beforePan = [touchView.offsetX, touchView.offsetY];
+ await nativeTouch([
+ {type: "touchStart", touchPoints: [from]},
+ {type: "touchMove", touchPoints: [{...from, x: from.x + 40, y: from.y + 20}]},
+ {type: "wait", delay: 520},
+ {type: "touchEnd", touchPoints: []},
+ ]);
+ check.notDeepEqual([touchView.offsetX, touchView.offsetY], beforePan, "native swipes pan even when starting on a node");
+ check.equal(touchMoves.length, 0);
+ check.equal(touchView.getSelectedId(), initialSelection, "swiping a dense map does not select incidental nodes");
+ check.equal(touchModel.list.outerHTML, originalHTML);
+ touchView.fit();
+ await settle();
+ const heldFrom = point(firstId);
+ const destination = point(lastId);
+ await nativeTouch([
+ {type: "touchStart", touchPoints: [heldFrom]},
+ {type: "wait", delay: 520},
+ {type: "touchMove", touchPoints: [destination]},
+ {type: "touchEnd", touchPoints: []},
+ ]);
+ check.equal(touchMoves.length, 1, "a completed native long press allows one node move on release");
+ check.equal(touchMoves[0][0], firstId);
+ check.equal(touchMoves[0][1], lastId);
+ check.equal(touchNode().classList.contains("mindmap-view__node--drag-ready"), false);
+ const sendTouch = (type: string) => touchNode().dispatchEvent(new PointerEvent(type, {
+ bubbles: true, cancelable: true, pointerId: 71, pointerType: "touch", isPrimary: true,
+ button: 0, clientX: heldFrom.x, clientY: heldFrom.y,
+ }));
+ sendTouch("pointerdown");
+ await new Promise(resolve => setTimeout(resolve, 500));
+ check.equal(touchNode().classList.contains("mindmap-view__node--drag-ready"), true, "holding provides visible drag feedback");
+ sendTouch("pointercancel");
+ check.equal(touchNode().classList.contains("mindmap-view__node--drag-ready"), false);
+ check.equal(touchMoves.length, 1, "cancellation does not submit the armed drag");
+ sendTouch("pointerdown");
+ sendTouch("pointerup");
+ await new Promise(resolve => setTimeout(resolve, 500));
+ check.equal(touchNode().classList.contains("mindmap-view__node--drag-ready"), false, "a short tap leaves no delayed drag");
+ check.equal(touchView.getSelectedId(), firstId, "short taps still select a node");
+ touchView.setReadOnly(true);
+ sendTouch("pointerdown");
+ await new Promise(resolve => setTimeout(resolve, 500));
+ check.equal(touchView.pointer?.touchNode, undefined, "read-only maps never arm a node move");
+ sendTouch("pointerup");
+ touchView.destroy();
+ touchHost.remove();
+ const fallbackHost = document.createElement("div");
+ const fallback = new api.ListMindmapView({...options, host: fallbackHost, onSettingsMenu: undefined, readOnly: true});
+ check.equal(fallbackHost.querySelector<HTMLButtonElement>('[aria-label="cursorHand"]').hidden, false,
+ "standalone export retains a usable fallback when no application menu is available");
+ fallback.destroy();
+ }
+
lute.SetTabs(true);
const tabsContainer = document.createElement("div");
tabsContainer.innerHTML = lute.Md2BlockDOM("::: tabs\n@tab First\n\nOne\n@tab Second\n\nTwo\n:::\n");
@@ -5022,6 +5113,10 @@ app.whenReady().then(async () => {
await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled", {enabled: true, maxTouchPoints: 2});
try {
for (const event of events) {
+ if (event.type === "wait") {
+ await new Promise(resolve => setTimeout(resolve, event.delay));
+ continue;
+ }
await win.webContents.debugger.sendCommand("Input.dispatchTouchEvent", event);
await new Promise(resolve => setTimeout(resolve, 30));
}
diff --git a/app/src/protyle/render/listMindmap/pinch.test.ts b/app/src/protyle/render/listMindmap/pinch.test.ts
index b6d002108a..77822962ee 100644
--- a/app/src/protyle/render/listMindmap/pinch.test.ts
+++ b/app/src/protyle/render/listMindmap/pinch.test.ts
@@ -114,3 +114,13 @@ test("editing controls and touches outside the map do not activate pinch", () =>
target.pinchEnd(event());
assert.equal(target.pinching, false);
});
+
+test("additional contacts cancel a pending node hold even when a control or third finger prevents pinch", () => {
+ for (const contacts of [[touch(60), touch(160, 120, true)], [touch(60), touch(160), touch(260)]]) {
+ const {target, cancelled} = setup();
+ target.pointer = {touchNode: "child"};
+ target.pinchStart(event(...contacts));
+ assert.equal(cancelled(), 1);
+ assert.equal(target.pinching, false);
+ }
+});
diff --git a/app/src/protyle/render/listMindmap/preview.test.ts b/app/src/protyle/render/listMindmap/preview.test.ts
index 7523c43b8b..bab43bc62a 100644
--- a/app/src/protyle/render/listMindmap/preview.test.ts
+++ b/app/src/protyle/render/listMindmap/preview.test.ts
@@ -183,7 +183,7 @@ const cases = async (source: string, css: string) => {
const node = {id: "table-node", children: [] as unknown[], contentBlocks: [richTable], virtual: false};
const model = {root: node, nodes: new Map([[node.id, node]]), metadata: {nodes: {}, relations: [] as {id: string}[]}};
const view = Object.assign(new api.MindmapPreviewView(), {
- options: {}, persistedLocked: false, nodeElements: new Map([[node.id, nodeElement]]), folded: new Map(),
+ options: {}, persistedLocked: false, nodeElements: new Map([[node.id, nodeElement]]), folded: new Map(), selectedIds: new Set(),
cancelSummarySelection: () => {}, renderTask: () => {}, destroyContentViews: () => {},
label: (key: string) => key, updateRelations: () => {}, updateSummaries: () => {},
updateSelection: () => {}, renderInspector: () => {}, refreshLayout: () => {},
diff --git a/app/src/protyle/render/listMindmap/replay.test.ts b/app/src/protyle/render/listMindmap/replay.test.ts
index e7a26664ce..6a6ef6a5e9 100644
--- a/app/src/protyle/render/listMindmap/replay.test.ts
+++ b/app/src/protyle/render/listMindmap/replay.test.ts
@@ -9,8 +9,9 @@ const indexSource = createSourceFile("index.ts", readFileSync("src/protyle/rende
ScriptTarget.ES2021, true);
const controller = indexSource.statements.find(item => isClassDeclaration(item) && item.name?.text === "ListMindmapController");
assert.ok(controller && isClassDeclaration(controller));
-const replay = controller.members.find(item => item.name?.getText(indexSource) === "replay");
-const replaySource = compile(`class Controller { ${replay.getText(indexSource)} } globalThis.Controller = Controller;`);
+const replay = controller.members.filter(item => ["replay", "replaceSourceChildren"].includes(item.name?.getText(indexSource)));
+assert.equal(replay.length, 2);
+const replaySource = compile(`class Controller { ${replay.map(item => item.getText(indexSource)).join("\n")} } globalThis.Controller = Controller;`);
// 小型 DOM 替身验证对象身份和替换顺序;真实布局/选区另由 Electron 回归覆盖。
class ElementFixture {
diff --git a/app/src/protyle/render/listMindmap/touchDrag.test.ts b/app/src/protyle/render/listMindmap/touchDrag.test.ts
new file mode 100644
index 0000000000..2c404f149b
--- /dev/null
+++ b/app/src/protyle/render/listMindmap/touchDrag.test.ts
@@ -0,0 +1,116 @@
+import * as assert from "node:assert/strict";
+import {readFileSync} from "node:fs";
+import test from "node:test";
+import {runInNewContext} from "node:vm";
+import {createSourceFile, isClassDeclaration, ScriptTarget, transpileModule} from "typescript";
+
+const source = createSourceFile("view.ts", readFileSync("src/protyle/render/listMindmap/view.ts", "utf8"),
+ ScriptTarget.ES2021, true);
+const view = source.statements.find(item => isClassDeclaration(item) && item.name?.text === "ListMindmapView");
+assert.ok(view && isClassDeclaration(view));
+const names = ["readOnly", "startTouchNodeDrag", "pointerMove", "cancelPointer"];
+const methods = view.members.filter(item => item.name && names.includes(item.name.getText(source)));
+assert.equal(methods.length, names.length);
+const compiled = transpileModule(`class View {${methods.map(item => item.getText(source)).join("\n")}}
+globalThis.View = View;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
+
+const setup = () => {
+ const timers = new Map<number, () => void>();
+ let nextTimer = 0;
+ const classes = new Set<string>();
+ const selected: string[] = [];
+ const context: any = {
+ Constants: {TIMEOUT_LONGPRESS: 460},
+ window: {setTimeout: (callback: () => void) => { timers.set(++nextTimer, callback); return nextTimer; }},
+ clearTimeout: (id: number) => timers.delete(id), cancelAnimationFrame: () => {},
+ };
+ runInNewContext(compiled, context);
+ const element = {classList: {add: (name: string) => classes.add(name),
+ remove: (...names: string[]) => names.forEach(name => classes.delete(name))}};
+ const target = Object.assign(new context.View(), {
+ options: {}, model: {nodes: new Map([["child", {}]])},
+ nodeElements: new Map([["child", element]]), inspector: {}, summaryBox: {},
+ viewport: {classList: element.classList},
+ selectNode: (id: string) => selected.push(id), clearDrop: () => {},
+ setHoveredLine: () => {}, requestDraw: () => {},
+ boundedPan: (x: number, y: number) => ({x, y}),
+ pointer: {pointerId: 1, touchNode: "child", pan: true, startX: 0, startY: 0, x: 0, y: 0, moved: false},
+ });
+ const pointer = target.pointer;
+ target.startTouchNodeDrag(pointer);
+ return {target, pointer, timers, classes, selected, flush: () => {
+ const callbacks = [...timers.values()];
+ timers.clear();
+ callbacks.forEach(callback => callback());
+ }};
+};
+
+test("touch node dragging is armed only after the hold and provides visible feedback", () => {
+ const {target, pointer, classes, selected, flush} = setup();
+ assert.equal(pointer.id, undefined);
+ assert.equal(pointer.pan, true);
+ assert.equal(classes.size, 0);
+ flush();
+ assert.equal(pointer.id, "child");
+ assert.equal(pointer.pan, false);
+ assert.deepEqual(selected, ["child"]);
+ assert.equal(target.inspector.hidden, true);
+ assert.equal(target.suppressLinkClick, true);
+ assert.ok(classes.has("mindmap-view__node--drag-ready"));
+ target.cancelPointer();
+ assert.equal(classes.has("mindmap-view__node--drag-ready"), false);
+});
+
+test("a quick swipe starting on a node pans and permanently cancels the pending hold", () => {
+ const {target, pointer, timers, selected, flush} = setup();
+ target.pointerMove({pointerId: 1, clientX: 30, clientY: 20, preventDefault() {}});
+ assert.equal(pointer.id, undefined);
+ assert.equal(pointer.moved, true);
+ assert.equal(timers.size, 0);
+ assert.equal(target.offsetX, 30);
+ assert.equal(target.offsetY, 20);
+ flush();
+ assert.equal(pointer.id, undefined);
+ assert.deepEqual(selected, [], "panning across dense nodes does not change the selected node");
+});
+
+test("small finger jitter preserves the hold until the drag threshold is reached", () => {
+ const {target, pointer, flush} = setup();
+ target.pointerMove({pointerId: 1, clientX: 2, clientY: 2, preventDefault() {}});
+ assert.equal(pointer.moved, false);
+ flush();
+ assert.equal(pointer.id, "child");
+});
+
+test("cancellation and pointer replacement cannot leave a delayed node drag", () => {
+ for (const replace of [false, true]) {
+ const {target, pointer, timers, classes, flush} = setup();
+ const staleCallback = [...timers.values()][0];
+ if (replace) {
+ target.pointer = {pointerId: 2};
+ } else {
+ target.cancelPointer();
+ assert.equal(timers.size, 0);
+ }
+ staleCallback();
+ flush();
+ assert.equal(pointer.id, undefined);
+ assert.equal(classes.size, 0);
+ }
+});
+
+test("read-only, locked, gesture and selection modes, destroyed and removed-node states reject a pending hold", () => {
+ for (const mode of ["readOnly", "locked", "pinching", "panning", "multiSelect", "summarySelecting", "relationFrom", "destroyed", "removed"]) {
+ const {target, pointer, selected, flush} = setup();
+ if (mode === "readOnly") {
+ target.options.readOnly = true;
+ } else if (mode === "removed") {
+ target.model.nodes.clear();
+ } else {
+ target[mode] = true;
+ }
+ flush();
+ assert.equal(pointer.id, undefined, mode);
+ assert.deepEqual(selected, [], mode);
+ }
+});
diff --git a/app/src/protyle/render/listMindmap/view.ts b/app/src/protyle/render/listMindmap/view.ts
index f036a9118b..7ad74b4016 100644
--- a/app/src/protyle/render/listMindmap/view.ts
+++ b/app/src/protyle/render/listMindmap/view.ts
@@ -58,7 +58,8 @@ export interface ListMindmapViewOptions {
onFoldSiblings?: (id: string) => Promise<boolean>;
onFoldLevel?: (level: ListMindmapFoldTarget) => Promise<boolean>;
onExpandLevelMenu?: (anchor: HTMLElement, select: (level: ListMindmapFoldTarget) => void) => void;
- onSettingsMenu?: (anchor: HTMLElement, expand?: (level: ListMindmapFoldTarget) => void) => void;
+ onSettingsMenu?: (anchor: HTMLElement, expand?: (level: ListMindmapFoldTarget) => void,
+ pan?: {active: boolean, toggle: () => void}) => void;
onTaskToggle?: (id: string, cycle?: boolean) => void;
onTaskMenu?: (id: string, anchor: HTMLElement) => void;
onTabTaskToggle?: (id: string, itemId: string) => void;
@@ -84,6 +85,8 @@ interface PointerState {
pan?: boolean;
id?: string;
nodeId?: string;
+ touchNode?: string;
+ touchDragTimer?: number;
startX: number;
startY: number;
x: number;
@@ -283,13 +286,14 @@ export class ListMindmapView {
this.listen(this.viewport, "touchmove", this.pinchMove, {passive: false});
this.listen(this.viewport, "touchend", this.pinchEnd, {passive: false});
this.listen(this.viewport, "touchcancel", this.pinchEnd, {passive: false});
+ this.listen(this.viewport, "touchcancel", this.cancelPointer);
this.listen(window, "blur", () => {
this.pinching = false;
this.pinch = undefined;
this.setInteractionActive(false);
});
this.listen(this.viewport, "contextmenu", (event: MouseEvent) => {
- if (this.suppressPanContextMenu) {
+ if (this.suppressPanContextMenu || this.pointer?.touchNode) {
event.preventDefault();
}
});
@@ -590,17 +594,17 @@ export class ListMindmapView {
add("fullscreen", "fullscreen", "iconFullscreen", () => this.toggleFullscreen());
return;
}
+ if (this.options.onSettingsMenu) {
+ add("settings", "more", "iconMore", () => {
+ const selectedId = this.selectedId;
+ this.options.onSettingsMenu(this.buttons.get("settings"),
+ this.buttons.get("expandLevel").hidden ? level => this.finishThen(() => {
+ void this.expandToLevel(level, selectedId).catch(error => console.error(error));
+ }) : undefined, {active: this.panning, toggle: () => this.togglePanning()});
+ });
+ this.buttons.get("settings").setAttribute("aria-haspopup", "menu");
+ }
if (!this.readOnly) {
- if (this.options.onSettingsMenu) {
- add("settings", "more", "iconMore", () => {
- const selectedId = this.selectedId;
- this.options.onSettingsMenu(this.buttons.get("settings"),
- this.buttons.get("expandLevel").hidden ? level => this.finishThen(() => {
- void this.expandToLevel(level, selectedId).catch(error => console.error(error));
- }) : undefined);
- });
- this.buttons.get("settings").setAttribute("aria-haspopup", "menu");
- }
add("summary", "listMindmapSummary", "iconGroups", () => {
this.finishThen(() => {
this.setInteractionActive(true);
@@ -654,18 +658,7 @@ export class ListMindmapView {
button.before(control);
control.append(button, this.levelSelect);
}
- add("pan", "cursorHand", "iconPan", () => {
- this.finishThen(() => {
- this.setInteractionActive(true);
- this.finishRelationEdit?.(true);
- this.cancelPointer();
- this.setPanning(!this.panning);
- this.relationFrom = undefined;
- this.relationPreview = undefined;
- this.inspector.hidden = true;
- this.updateSelection();
- });
- });
+ add("pan", "cursorHand", "iconPan", () => this.togglePanning());
this.setPanning(this.panning);
const zoomControl = createElement("div", "mindmap-view__zoom-control");
const zoomActions = createElement("div", "mindmap-view__zoom-actions");
@@ -705,6 +698,22 @@ export class ListMindmapView {
}
}
+ private togglePanning() {
+ this.finishThen(() => {
+ if (this.locked || this.destroyed) {
+ return;
+ }
+ this.setInteractionActive(true);
+ this.finishRelationEdit?.(true);
+ this.cancelPointer();
+ this.setPanning(!this.panning);
+ this.relationFrom = undefined;
+ this.relationPreview = undefined;
+ this.inspector.hidden = true;
+ this.updateSelection();
+ });
+ }
+
private setPanning(value: boolean) {
if (value) {
this.cancelSummarySelection();
@@ -713,12 +722,15 @@ export class ListMindmapView {
this.options.host.classList.toggle("mindmap-view--pan", value);
this.viewport.classList.toggle("mindmap-view__viewport--pan", value);
const button = this.buttons.get("pan");
+ if (button) {
+ button.hidden = !!this.options.onSettingsMenu && !value;
+ }
button?.classList.toggle("block__icon--active", value);
button?.setAttribute("aria-pressed", String(value));
}
public update(model: ListMindmapModel) {
- if (this.pointer?.relation || this.pointer?.summary || this.pointer?.selection) {
+ if (this.pointer?.relation || this.pointer?.summary || this.pointer?.selection || this.pointer?.touchNode) {
this.cancelPointer();
}
if (this.destroyed) {
@@ -2233,6 +2245,9 @@ export class ListMindmapView {
}
private pinchStart = (event: TouchEvent) => {
+ if (event.touches.length > 1 && this.pointer?.touchNode) {
+ this.cancelPointer();
+ }
if (this.locked || event.touches.length !== 2 || Array.from(event.touches).some(touch =>
!this.viewport.contains(touch.target as Node) ||
((touch.target as Element).closest("button, input, select, textarea, audio, video, iframe") ||
@@ -2415,7 +2430,9 @@ export class ListMindmapView {
return;
}
if (id) {
- this.selectNode(id, event.button === 0 && (event.ctrlKey || event.metaKey || this.multiSelect));
+ if (event.pointerType !== "touch" || event.ctrlKey || event.metaKey || this.multiSelect) {
+ this.selectNode(id, event.button === 0 && (event.ctrlKey || event.metaKey || this.multiSelect));
+ }
if (event.ctrlKey || event.metaKey || this.multiSelect) {
this.suppressLinkClick = true;
this.options.host.focus({preventScroll: true});
@@ -2435,8 +2452,10 @@ export class ListMindmapView {
pointerId: event.pointerId,
rightButton: event.button === 2,
pan: this.panning || event.button === 2 || event.pointerType === "touch",
- id: !this.readOnly && id && !this.model.nodes.get(id)?.virtual ? id : undefined,
+ id: event.pointerType !== "touch" && !this.readOnly && id && !this.model.nodes.get(id)?.virtual ? id : undefined,
nodeId: id,
+ touchNode: event.pointerType === "touch" && !this.readOnly && this.options.onMove &&
+ id !== this.model.root.id && this.model.nodes.has(id) && !this.model.nodes.get(id).virtual ? id : undefined,
startX: event.clientX,
startY: event.clientY,
x: this.offsetX,
@@ -2450,11 +2469,35 @@ export class ListMindmapView {
// 在原点击元素捕获指针,保留链接目标,同时让连续点击可以识别为双击。
this.pointerCapture = id ? event.target as HTMLElement : this.viewport;
this.pointerCapture.setPointerCapture(event.pointerId);
+ if (this.pointer.touchNode) {
+ this.startTouchNodeDrag(this.pointer);
+ }
} catch {
this.cancelPointer();
}
}
+ private startTouchNodeDrag(pointer: PointerState) {
+ if (!pointer.touchNode) {
+ return;
+ }
+ // 快速滑动始终平移;只有在原节点上长按完成后才允许改变导图结构。
+ pointer.touchDragTimer = window.setTimeout(() => {
+ pointer.touchDragTimer = undefined;
+ if (this.pointer !== pointer || pointer.moved || this.readOnly || this.pinching || this.panning ||
+ this.multiSelect || this.summarySelecting || this.relationFrom ||
+ this.destroyed || !this.model.nodes.has(pointer.touchNode)) {
+ return;
+ }
+ pointer.id = pointer.touchNode;
+ pointer.pan = false;
+ this.selectNode(pointer.id);
+ this.inspector.hidden = true;
+ this.suppressLinkClick = true;
+ this.nodeElements.get(pointer.id)?.classList.add("mindmap-view__node--drag-ready");
+ }, Constants.TIMEOUT_LONGPRESS);
+ }
+
private pointerMove = (event: PointerEvent) => {
if (this.pinching) {
return;
@@ -2493,6 +2536,8 @@ export class ListMindmapView {
if (!pointer.moved && Math.hypot(dx, dy) < 5) {
return;
}
+ clearTimeout(pointer.touchDragTimer);
+ pointer.touchDragTimer = undefined;
event.preventDefault();
if (!pointer.moved && (pointer.id || pointer.pan)) {
pointer.hiddenControls?.forEach(element => element.classList.add("mindmap-view__node--hide-controls"));
@@ -2706,8 +2751,11 @@ export class ListMindmapView {
}
return;
}
- this.suppressLinkClick = moved;
+ this.suppressLinkClick = moved || !!pointer.touchNode && !!id;
this.cancelPointer();
+ if (!moved && !id && event.pointerType === "touch" && pointer.nodeId && !this.panning) {
+ this.selectNode(pointer.nodeId);
+ }
if (moved && id && targetId && placement) {
this.options.onMove?.(id, targetId, placement);
} else if (!moved && !pointer.nodeId && !pointer.rightButton && !this.readOnly && !this.panning) {
@@ -2804,6 +2852,7 @@ export class ListMindmapView {
this.clearDrop();
const pointer = this.pointer;
this.pointer = undefined;
+ clearTimeout(pointer?.touchDragTimer);
pointer?.hiddenControls?.forEach(element => element.classList.remove("mindmap-view__node--hide-controls"));
this.summaryBox.hidden = true;
if (pointer?.summary) {
@@ -2821,7 +2870,7 @@ export class ListMindmapView {
this.ghost?.remove();
this.ghost = undefined;
this.viewport.classList.remove("mindmap-view__viewport--dragging");
- this.nodeElements.forEach(element => element.classList.remove("mindmap-view__node--dragging"));
+ this.nodeElements.forEach(element => element.classList.remove("mindmap-view__node--dragging", "mindmap-view__node--drag-ready"));
if (pointer?.relation) {
if (pointer.relation.endpoint) {
this.nodeElements.forEach(element => element.classList.remove("mindmap-view__node--relation"));
diff --git a/app/src/protyle/render/listMindmap/wheel.test.ts b/app/src/protyle/render/listMindmap/wheel.test.ts
index 1451cdb34d..eb4d56b422 100644
--- a/app/src/protyle/render/listMindmap/wheel.test.ts
+++ b/app/src/protyle/render/listMindmap/wheel.test.ts
@@ -19,7 +19,7 @@ globalThis.View = View;`, {compilerOptions: {target: ScriptTarget.ES2021}}).outp
const setup = () => {
const frames: (() => void)[] = [];
- const context: any = {clampMindmapPanOffset, clampMindmapPanPosition, WheelEvent: {DOM_DELTA_LINE: 1, DOM_DELTA_PAGE: 2},
+ const context: any = {clearTimeout, clampMindmapPanOffset, clampMindmapPanPosition, WheelEvent: {DOM_DELTA_LINE: 1, DOM_DELTA_PAGE: 2},
requestAnimationFrame: (action: () => void) => frames.push(action)};
runInNewContext(compiled, context);
const target = new context.View();