Skip to content

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

:bug: Preserve mobile block multi-select activation https://github.com/siyuan-note/siyuan/issues/18844

Danielfd7e51ab3855
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index d3349540d7..c19b3f8c79 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -18,7 +18,7 @@ import {
hasVisibleSelectionText,
shouldRestoreLongPressSelection,
} from "./touchSelection";
-import {getTouchAxis, shouldEnterLongPressMultiSelect} from "./touchGesture";
+import {getTouchAxis, shouldStartLongPressMultiSelect} from "./touchGesture";
let clientX: number;
let clientY: number;
@@ -349,7 +349,13 @@ export const handleTouchStart = (event: TouchEvent) => {
clearLongPress();
if (clientX && clientY && editor && !editor.protyle.toolbar.isMultiSelectMode()) {
const blockElement = hasClosestBlock(target);
- if (blockElement && editor.protyle.wysiwyg.element.contains(blockElement)) {
+ if (blockElement && editor.protyle.wysiwyg.element.contains(blockElement) &&
+ shouldStartLongPressMultiSelect(
+ target.tagName,
+ target.dataset.type,
+ !!hasClosestByAttribute(target, "data-type", "inline-math"),
+ target.tagName === "IMG" && !!hasClosestByClassName(target, "img"),
+ )) {
longPressBlockElement = blockElement;
const touchRange = getRangeByPoint(event.touches[0].clientX, event.touches[0].clientY);
const touchRangeElement = touchRange.startContainer.nodeType === Node.ELEMENT_NODE ?
@@ -360,13 +366,6 @@ export const handleTouchStart = (event: TouchEvent) => {
longPressTouchRange.collapse(true);
}
longPressTimer = window.setTimeout(() => {
- if (!shouldEnterLongPressMultiSelect(
- !window.siyuan.menus.menu.element.classList.contains("fn__none"),
- !editor.protyle.toolbar.subElement.classList.contains("fn__none"),
- )) {
- longPressTimer = undefined;
- return;
- }
clearInvisibleEditorSelection();
const selection = window.getSelection();
if (selection?.rangeCount > 0) {
diff --git a/app/src/mobile/util/touchGesture.test.ts b/app/src/mobile/util/touchGesture.test.ts
index 4d605f109b..ca6fda14b4 100644
--- a/app/src/mobile/util/touchGesture.test.ts
+++ b/app/src/mobile/util/touchGesture.test.ts
@@ -1,6 +1,6 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {getTouchAxis, shouldEnterLongPressMultiSelect} from "./touchGesture";
+import {getTouchAxis, shouldStartLongPressMultiSelect} from "./touchGesture";
describe("mobile touch gesture", () => {
it("waits for the drag threshold before locking the gesture axis", () => {
@@ -13,10 +13,17 @@ describe("mobile touch gesture", () => {
assert.equal(getTouchAxis(4, 12, 5), "y");
});
- it("does not enter multi-select while another long-press action is open", () => {
- assert.equal(shouldEnterLongPressMultiSelect(true, false), false);
- assert.equal(shouldEnterLongPressMultiSelect(false, true), false);
- assert.equal(shouldEnterLongPressMultiSelect(true, true), false);
- assert.equal(shouldEnterLongPressMultiSelect(false, false), true);
+ it("does not start multi-select for elements with dedicated long-press actions", () => {
+ ["block-ref", "file-annotation-ref", "tag", "inline-memo", "a"].forEach(type => {
+ assert.equal(shouldStartLongPressMultiSelect("SPAN", type, false, false), false);
+ });
+ assert.equal(shouldStartLongPressMultiSelect("SPAN", "strong a", false, false), false);
+ assert.equal(shouldStartLongPressMultiSelect("PROTYLE-HTML", undefined, true, false), false);
+ assert.equal(shouldStartLongPressMultiSelect("IMG", undefined, false, true), false);
+ });
+
+ it("starts multi-select for ordinary block content", () => {
+ assert.equal(shouldStartLongPressMultiSelect("DIV", undefined, false, false), true);
+ assert.equal(shouldStartLongPressMultiSelect("SPAN", "strong", false, false), true);
});
});
diff --git a/app/src/mobile/util/touchGesture.ts b/app/src/mobile/util/touchGesture.ts
index e1eaa2410b..c15a7434a7 100644
--- a/app/src/mobile/util/touchGesture.ts
+++ b/app/src/mobile/util/touchGesture.ts
@@ -7,7 +7,11 @@ export const getTouchAxis = (xDiff: number, yDiff: number, threshold: number): T
return Math.abs(xDiff) > Math.abs(yDiff) ? "x" : "y";
};
-export const shouldEnterLongPressMultiSelect = (
- commonMenuOpen: boolean,
- toolbarSubElementOpen: boolean,
-) => !commonMenuOpen && !toolbarSubElementOpen;
+export const shouldStartLongPressMultiSelect = (
+ tagName: string,
+ dataType: string | undefined,
+ insideInlineMath: boolean,
+ imageMenuTarget: boolean,
+) => !(tagName === "SPAN" && (dataType || "").split(" ").some(type =>
+ ["block-ref", "file-annotation-ref", "tag", "inline-memo", "a"].includes(type))) &&
+ !insideInlineMath && !imageMenuTarget;