Skip to content

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

:bug: Fix mobile pinned document touch sorting https://github.com/siyuan-note/siyuan/issues/19401

Daniel200cb2c594e4
diff --git a/app/src/layout/dock/PinnedDocs.test.ts b/app/src/layout/dock/PinnedDocs.test.ts
index 5bb5263cef..8b3e900fca 100644
--- a/app/src/layout/dock/PinnedDocs.test.ts
+++ b/app/src/layout/dock/PinnedDocs.test.ts
@@ -31,6 +31,8 @@ interface IPanelHarness {
scheduleRefresh(changedID?: string): void;
dropTarget?: {id: string, position: string};
suppressClick?: boolean;
+ touch?: {dragging: boolean};
+ contextMenu(event: unknown): void;
}
const loadPanel = (fetchCode = 0) => {
@@ -140,6 +142,38 @@ test("pinned roots share one list and retain each document notebook without wrap
assert.equal(children[3].dataset.url, "second");
});
+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"}};
+ let prevented = 0;
+ const event = {stopPropagation: () => {}, preventDefault: () => prevented++,
+ target: {closest: () => row}, clientX: 10, clientY: 20};
+ for (const dragging of [false, true]) {
+ panel.touch = {dragging};
+ panel.contextMenu(event);
+ }
+ panel.touch = undefined;
+ panel.suppressClick = true;
+ panel.contextMenu(event);
+ assert.equal(calls.length, 0);
+ assert.equal(prevented, 3);
+ panel.suppressClick = false;
+ panel.contextMenu(event);
+ assert.equal(calls[0].kind, "menu");
+});
+
+test("mobile pinned rows use touch dragging without native HTML dragging", async () => {
+ const {panel} = loadPanel();
+ panel.expanded = new Set();
+ for (const mobile of [false, true]) {
+ panel.mobile = mobile;
+ const children: {draggable?: boolean}[] = [];
+ const parent = {append: (child: typeof children[number]) => children.push(child)};
+ await panel.appendDoc(parent, {id: "doc", notebook: "box", name: "Document", path: "/doc.sy", subFileCount: 0}, "doc", 0, 0);
+ assert.equal(children[0].draggable, !mobile);
+ }
+});
+
test("pinned icons respect editing, expansion and readonly settings", () => {
const {panel, calls, config} = loadPanel();
const row = {dataset: {nodeId: "document", notebook: "notebook", count: "1"}, classList: {add: () => {}}};
diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.ts
index da2e336907..e8cb672c3a 100644
--- a/app/src/layout/dock/PinnedDocs.ts
+++ b/app/src/layout/dock/PinnedDocs.ts
@@ -92,14 +92,7 @@ export class PinnedDocs {
}
this.setCollapsed(localStorage.getItem("siyuan-pinned-docs-collapsed") === "true");
this.element.addEventListener("click", event => this.click(event));
- this.element.addEventListener("contextmenu", event => {
- event.stopPropagation();
- const row = (event.target as Element).closest<HTMLElement>("[data-pin-row]");
- if (row) {
- event.preventDefault();
- this.menu(row, event.clientX, event.clientY);
- }
- });
+ this.element.addEventListener("contextmenu", event => this.contextMenu(event));
this.element.addEventListener("dragstart", event => {
const row = (event.target as Element).closest<HTMLElement>("[data-pin-row]");
if (!row || row.dataset.unavailable === "true" || window.siyuan.config.readonly) {
@@ -275,7 +268,7 @@ export class PinnedDocs {
row.dataset.type = "navigation-file";
row.setAttribute(FILE_TREE_CHILDREN_SORT_MODE, doc.childrenSortMode?.toString() || "");
row.dataset.unavailable = String(Boolean(doc.unavailable));
- row.draggable = !doc.unavailable && !window.siyuan.config.readonly;
+ row.draggable = !this.mobile && !doc.unavailable && !window.siyuan.config.readonly;
row.tabIndex = 0;
const paddingLeft = (depth + 1) * (this.mobile ? 20 : 18);
row.style.setProperty("--file-toggle-width", `${paddingLeft + 18}px`);
@@ -502,6 +495,17 @@ export class PinnedDocs {
this.scheduleRefresh();
}
+ private contextMenu(event: MouseEvent) {
+ event.stopPropagation();
+ const row = (event.target as Element).closest<HTMLElement>("[data-pin-row]");
+ if (row) {
+ event.preventDefault();
+ // 触摸长按由拖拽处理,避免弹出菜单中断手势。
+ if (this.touch || this.suppressClick) { return; }
+ this.menu(row, event.clientX, event.clientY);
+ }
+ }
+
private cancelTouch() {
this.clearDrop();
if (this.touch) {
@@ -514,13 +518,14 @@ export class PinnedDocs {
private bindTouch() {
this.element.addEventListener("touchstart", event => {
event.stopPropagation();
+ this.cancelTouch();
const row = (event.target as Element).closest<HTMLElement>("[data-pin-row]");
if (!row || row.dataset.unavailable === "true" || window.siyuan.config.readonly || event.touches.length !== 1) { return; }
- this.cancelTouch();
const touch = event.touches[0];
const state = {id: row.dataset.nodeId, x: touch.clientX, y: touch.clientY, timer: 0, dragging: false, ghost: undefined as HTMLElement};
this.touch = state;
state.timer = window.setTimeout(() => {
+ if (this.touch !== state) { return; }
state.dragging = true;
state.ghost = row.cloneNode(true) as HTMLElement;
state.ghost.style.cssText = `position:fixed;pointer-events:none;z-index:9999;opacity:.7;left:${state.x}px;top:${state.y}px`;
@@ -531,6 +536,7 @@ export class PinnedDocs {
this.element.addEventListener("touchmove", event => {
event.stopPropagation();
if (!this.touch) { return; }
+ if (event.touches.length !== 1) { this.cancelTouch(); return; }
const touch = event.touches[0];
if (!this.touch.dragging) {
if (Math.abs(touch.clientX - this.touch.x) + Math.abs(touch.clientY - this.touch.y) > 8) { this.cancelTouch(); }