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/17612

Vanessa2f8b7a35b553
diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.ts
index 47a5b442f8..ff37c16868 100644
--- a/app/src/boot/globalEvent/event.ts
+++ b/app/src/boot/globalEvent/event.ts
@@ -6,15 +6,8 @@ import {globalClick} from "./click";
import {goBack, goForward} from "../../util/backForward";
import {Constants} from "../../constants";
import {isIPad} from "../../protyle/util/compatibility";
-import {globalTouchEnd} from "./touch";
-import {initDockMenu} from "../../menus/dock";
-import {hasClosestByAttribute, hasClosestByClassName, isInEmbedBlock} from "../../protyle/util/hasClosest";
-import {initTabMenu} from "../../menus/tab";
-import {getInstanceById} from "../../layout/util";
-import {Tab} from "../../layout/Tab";
+import {hasClosestByClassName, isInEmbedBlock} from "../../protyle/util/hasClosest";
import {hideTooltip} from "../../dialog/tooltip";
-import {openFileById} from "../../editor/util";
-import {checkFold} from "../../util/noRelyPCFunction";
import {hideAllElements} from "../../protyle/ui/hideElements";
import {dragOverScroll, stopScrollAnimation} from "./dragover";
import {setWebViewFocusable} from "../../mobile/util/mobileAppUtil";
@@ -154,60 +147,16 @@ export const initWindowEvent = (app: App) => {
return;
}
// pad 端长按事件
- if (isIPad()) {
- // https://github.com/siyuan-note/siyuan/issues/9113
- if (globalTouchEnd(event, undefined, time, app)) {
- event.stopImmediatePropagation();
- event.preventDefault();
- return;
- }
- if (new Date().getTime() - time <= 900) {
- return;
- }
- const target = event.target as HTMLElement;
- // dock right menu
- const dockElement = hasClosestByClassName(target, "dock__item");
- if (dockElement && dockElement.getAttribute("data-type")) {
- const dockRect = dockElement.getBoundingClientRect();
- initDockMenu(dockElement).popup({x: dockRect.right, y: dockRect.top});
- event.stopImmediatePropagation();
- event.preventDefault();
- return;
- }
-
- // tab right menu
- const tabElement = hasClosestByAttribute(target, "data-type", "tab-header");
- if (tabElement) {
- const tabRect = tabElement.getBoundingClientRect();
- initTabMenu(app, (getInstanceById(tabElement.getAttribute("data-id")) as Tab)).popup({
- x: tabRect.left,
- y: tabRect.bottom
- });
- hideTooltip();
- event.stopImmediatePropagation();
- event.preventDefault();
- return;
- }
-
- const backlinkBreadcrumbItemElement = hasClosestByClassName(target, "protyle-breadcrumb__item");
- if (backlinkBreadcrumbItemElement) {
- const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id") || backlinkBreadcrumbItemElement.getAttribute("data-node-id");
- if (breadcrumbId) {
- checkFold(breadcrumbId, (zoomIn) => {
- openFileById({
- app,
- id: breadcrumbId,
- action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
- zoomIn,
- });
- window.siyuan.menus.menu.remove();
- });
- }
- event.stopImmediatePropagation();
- event.preventDefault();
- return;
- }
+ if (isIPad() && new Date().getTime() - time > 900) {
+ event.target.dispatchEvent(new MouseEvent("contextmenu", {
+ bubbles: true,
+ cancelable: true,
+ clientX: event.changedTouches[0].clientX,
+ clientY: event.changedTouches[0].clientY,
+ }));
+ event.stopImmediatePropagation();
+ event.preventDefault();
}
- }, false);
+ });
initTouchDragBridge();
};
diff --git a/app/src/boot/globalEvent/touch.ts b/app/src/boot/globalEvent/touch.ts
deleted file mode 100644
index 2d0f5e0f18..0000000000
--- a/app/src/boot/globalEvent/touch.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-import {isIPad} from "../../protyle/util/compatibility";
-import {
- hasClosestByAttribute,
- hasClosestByClassName,
- hasTopClosestByTag,
- isInEmbedBlock
-} from "../../protyle/util/hasClosest";
-import {initFileMenu, initNavigationMenu} from "../../menus/navigation";
-import {fileAnnotationRefMenu, inlineMathMenu, linkMenu, refMenu, tagMenu} from "../../menus/protyle";
-import {App} from "../../index";
-import {Protyle} from "../../protyle";
-import {getCurrentEditor} from "../../mobile/editor";
-/// #if !MOBILE
-import {getInstanceById} from "../../layout/util";
-import {Tab} from "../../layout/Tab";
-/// #endif
-import {Editor} from "../../editor";
-import {hideTooltip} from "../../dialog/tooltip";
-
-export const globalTouchEnd = (event: TouchEvent, yDiff: number, time: number, app: App) => {
- const target = event.target as HTMLElement;
- const isIPadBoolean = isIPad();
- if (typeof yDiff === "undefined" && new Date().getTime() - time > 900) {
- // ios 长按
- // 文档树
- const fileItemElement = hasClosestByAttribute(target, "data-type", "navigation-root") || hasClosestByAttribute(target, "data-type", "navigation-file");
- if (fileItemElement) {
- if (!window.siyuan.config.readonly && fileItemElement.dataset.type === "navigation-root") {
- const menu = initNavigationMenu(app, fileItemElement);
- if (isIPadBoolean) {
- const rect = fileItemElement.getBoundingClientRect();
- menu.popup({x: rect.right - 52, y: rect.bottom, h: rect.height});
- hideTooltip();
- } else {
- window.siyuan.menus.menu.fullscreen("bottom");
- }
- } else if (fileItemElement.dataset.type === "navigation-file") {
- const rootElement = hasTopClosestByTag(fileItemElement, "UL");
- if (rootElement) {
- const menu = initFileMenu(app, rootElement.dataset.url, fileItemElement.dataset.path, fileItemElement);
- if (isIPadBoolean) {
- const rect = fileItemElement.getBoundingClientRect();
- menu.popup({x: rect.right - 52, y: rect.bottom, h: rect.height});
- hideTooltip();
- } else {
- window.siyuan.menus.menu.fullscreen("bottom");
- }
- }
- }
- return true;
- }
- // 内元素弹出菜单
- if (target.tagName === "SPAN" && !isInEmbedBlock(target)) {
- let editor: Protyle;
- /// #if !MOBILE
- const tabContainerElement = hasClosestByClassName(target, "protyle", true);
- if (tabContainerElement) {
- const tab = getInstanceById(tabContainerElement.dataset.id);
- if (tab instanceof Tab && tab.model instanceof Editor) {
- editor = tab.model.editor;
- }
- }
- /// #else
- if (hasClosestByClassName(target, "protyle-wysiwyg", true)) {
- editor = getCurrentEditor();
- }
- /// #endif
- if (!editor) {
- return false;
- }
- const types = (target.getAttribute("data-type") || "").split(" ");
- if (types.includes("inline-memo")) {
- editor.protyle.toolbar.showRender(editor.protyle, target);
- }
- if (editor.protyle.disabled) {
- event.stopImmediatePropagation();
- event.preventDefault();
- return true;
- }
- if (types.includes("block-ref")) {
- refMenu(editor.protyle, target);
- return true;
- }
- if (types.includes("file-annotation-ref")) {
- fileAnnotationRefMenu(editor.protyle, target);
- return true;
- }
- if (types.includes("tag")) {
- tagMenu(editor.protyle, target);
- return true;
- }
- if (types.includes("a")) {
- linkMenu(editor.protyle, target);
- return true;
- }
- const inlineMathElement = hasClosestByAttribute(target, "data-type", "inline-math");
- if (inlineMathElement) {
- inlineMathMenu(editor.protyle, inlineMathElement);
- return true;
- }
- }
- }
- return false;
-};
diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts
index be16917bcf..88e7210481 100644
--- a/app/src/mobile/index.ts
+++ b/app/src/mobile/index.ts
@@ -174,9 +174,7 @@ class App {
});
document.addEventListener("touchstart", handleTouchStart, false);
document.addEventListener("touchmove", handleTouchMove, false);
- document.addEventListener("touchend", (event) => {
- handleTouchEnd(event, siyuanApp);
- }, false);
+ document.addEventListener("touchend", handleTouchEnd, 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 5e2f1d1132..b0148fcbd4 100644
--- a/app/src/mobile/util/touch.ts
+++ b/app/src/mobile/util/touch.ts
@@ -8,8 +8,6 @@ import {closeModel, closePanel} from "./closePanel";
import {popMenu} from "../menu";
import {activeBlur} from "./keyboardToolbar";
import {isIPhone} from "../../protyle/util/compatibility";
-import {App} from "../../index";
-import {globalTouchEnd} from "../../boot/globalEvent/touch";
import {getRangeByPoint} from "../../protyle/util/selection";
import {getCurrentEditor} from "../editor";
@@ -33,13 +31,21 @@ const popSide = (render = true) => {
}
};
-export const handleTouchEnd = (event: TouchEvent, app: App) => {
+export const handleTouchEnd = (event: TouchEvent) => {
const target = event.target as HTMLElement;
- if (isIPhone() && globalTouchEnd(event, yDiff, time, app)) {
+
+ if (isIPhone() && typeof yDiff === "undefined" && new Date().getTime() - time > 900) {
+ target.dispatchEvent(new MouseEvent("contextmenu", {
+ bubbles: true,
+ cancelable: true,
+ clientX: event.changedTouches[0].clientX,
+ clientY: event.changedTouches[0].clientY,
+ }));
event.stopImmediatePropagation();
event.preventDefault();
return;
}
+
if (typeof yDiff === "undefined" && window.siyuan.mobile.editor.protyle.options.render.gutter) {
const nodeElement = hasClosestBlock(target);
if (nodeElement) {