Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/13207

Vanessa6b6da39299f3
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index c368c70a35..9cd496c1ee 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -12,7 +12,7 @@ import {Model} from "../layout/Model";
import "../assets/scss/mobile.scss";
import {Menus} from "../menus";
import {addBaseURL, parseSiYuanUriInfo, setNoteBook} from "../util/pathName";
-import {clearLongPress, handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
+import {handlePointerUp, handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
import {fetchGet, fetchPost} from "../util/fetch";
import {initFramework} from "./util/initFramework";
import {initAssets} from "../util/assets";
@@ -179,10 +179,7 @@ class App {
document.addEventListener("touchmove", handleTouchMove, false);
document.addEventListener("touchend", handleTouchEnd, false);
document.addEventListener("touchcancel", handleTouchEnd, false);
- // 系统长按选中文本会接管触摸事件,touchend 可能收不到,用 pointerup 兜底清除多选定定时器
- window.addEventListener("pointerup", () => {
- clearLongPress();
- });
+ window.addEventListener("pointerup", handlePointerUp, false);
window.addEventListener("keyup", () => {
window.siyuan.ctrlIsPressed = false;
window.siyuan.shiftIsPressed = false;
diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts
index 500f077a0a..edb2a0a6e4 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -35,13 +35,19 @@ const popSide = (render = true) => {
};
// 清除长按进入多选的定时器
-export const clearLongPress = () => {
+const clearLongPress = () => {
if (longPressTimer) {
clearTimeout(longPressTimer);
longPressTimer = undefined;
}
};
+export const handlePointerUp = () => {
+ if (Date.now() - time < Constants.TIMEOUT_MULTIPLE_SELECT) {
+ clearLongPress();
+ }
+};
+
export const handleTouchEnd = (event: TouchEvent) => {
const target = event.target as HTMLElement;
const currentTime = Date.now();
@@ -49,7 +55,6 @@ export const handleTouchEnd = (event: TouchEvent) => {
if (Math.abs(clientX - event.changedTouches[0].clientX) < 5 && Math.abs(clientY - event.changedTouches[0].clientY) < 5) {
if (editor && editor.protyle.toolbar.isMultiSelectMode()) {
if (longPressTimer) {
- clearLongPress();
event.stopImmediatePropagation();
event.preventDefault();
return;
@@ -83,13 +88,11 @@ export const handleTouchEnd = (event: TouchEvent) => {
clientY: event.changedTouches[0].clientY,
}));
}
- clearLongPress();
event.stopImmediatePropagation();
event.preventDefault();
return;
}
}
- clearLongPress();
if (typeof yDiff === "undefined" && window.siyuan.mobile.editor?.protyle.options.render.gutter) {
const nodeElement = hasClosestBlock(target);
if (nodeElement) {
@@ -254,19 +257,7 @@ export const handleTouchStart = (event: TouchEvent) => {
const blockElement = hasClosestBlock(target);
if (blockElement && editor.protyle.wysiwyg.element.contains(blockElement)) {
longPressTimer = window.setTimeout(() => {
- // 原生长按选中文本后继续按压,达到阈值进入块多选模式
- const selection = window.getSelection();
- if (selection && selection.toString() !== "") {
- setTimeout(() => {
- if (longPressTimer) {
- selection?.removeAllRanges();
- activeBlur();
- editor.protyle.toolbar.showMultiSelectMode(editor.protyle, blockElement);
- }
- }, 1000);
- return;
- }
- selection?.removeAllRanges();
+ window.getSelection()?.removeAllRanges();
activeBlur();
editor.protyle.toolbar.showMultiSelectMode(editor.protyle, blockElement);
}, Constants.TIMEOUT_MULTIPLE_SELECT);