From 2bbc9fb74bc4d989755bb2fedc5447e0886cd5a6 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 7 Sep 2023 09:58:07 +0800 Subject: [PATCH] :iphone: fix https://github.com/siyuan-note/siyuan/issues/9111 --- app/src/boot/globalEvent/touch.ts | 91 +++++++++++++++++++++++++++++++ app/src/mobile/util/touch.ts | 51 ++--------------- 2 files changed, 97 insertions(+), 45 deletions(-) create mode 100644 app/src/boot/globalEvent/touch.ts diff --git a/app/src/boot/globalEvent/touch.ts b/app/src/boot/globalEvent/touch.ts new file mode 100644 index 000000000..4e47e9066 --- /dev/null +++ b/app/src/boot/globalEvent/touch.ts @@ -0,0 +1,91 @@ +import {isIPad, isIPhone} from "../../protyle/util/compatibility"; +import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByTag} from "../../protyle/util/hasClosest"; +import {initFileMenu, initNavigationMenu} from "../../menus/navigation"; +import {fileAnnotationRefMenu, linkMenu, refMenu, tagMenu} from "../../menus/protyle"; +import {App} from "../../index"; +import {Protyle} from "../../protyle"; +import {getCurrentEditor} from "../../mobile/editor"; +import {getInstanceById} from "../../layout/util"; +import {Tab} from "../../layout/Tab"; +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; + 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 (isIPad()) { + const rect = fileItemElement.getBoundingClientRect() + menu.popup({x: rect.right, 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 (isIPad()) { + const rect = fileItemElement.getBoundingClientRect() + menu.popup({x: rect.right, y: rect.bottom, h: rect.height}) + hideTooltip() + } else { + window.siyuan.menus.menu.fullscreen("bottom"); + } + } + } + return true; + } + // 内元素弹出菜单 + if (target.tagName === "SPAN" && !hasClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed")) { + let editor: Protyle + if (isIPhone()) { + if (hasClosestByClassName(target, "protyle-wysiwyg")) { + editor = getCurrentEditor(); + } + } else { + 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 + } + } + } + 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; + } + } + } + return false +} diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.ts index 444640f47..173442585 100644 --- a/app/src/mobile/util/touch.ts +++ b/app/src/mobile/util/touch.ts @@ -7,11 +7,9 @@ import { import {closePanel} from "./closePanel"; import {popMenu} from "../menu"; import {activeBlur, hideKeyboardToolbar} from "./keyboardToolbar"; -import {getCurrentEditor} from "../editor"; -import {fileAnnotationRefMenu, linkMenu, refMenu, tagMenu} from "../../menus/protyle"; import {isIPhone} from "../../protyle/util/compatibility"; -import {initFileMenu, initNavigationMenu} from "../../menus/navigation"; import {App} from "../../index"; +import {globalTouchEnd} from "../../boot/globalEvent/touch"; let clientX: number; let clientY: number; @@ -32,49 +30,12 @@ const popSide = (render = true) => { }; export const handleTouchEnd = (event: TouchEvent, app: App) => { - const editor = getCurrentEditor(); - const target = event.target as HTMLElement; - if (typeof yDiff === "undefined" && new Date().getTime() - time > 900 && isIPhone()) { - // 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") { - initNavigationMenu(app, fileItemElement); - window.siyuan.menus.menu.fullscreen("bottom"); - } else if (fileItemElement.dataset.type === "navigation-file") { - const rootElement = hasTopClosestByTag(fileItemElement, "UL"); - if (rootElement) { - initFileMenu(app, rootElement.dataset.url, fileItemElement.dataset.path, fileItemElement); - window.siyuan.menus.menu.fullscreen("bottom"); - } - } - event.stopImmediatePropagation(); - event.preventDefault(); - return; - } - // 内元素弹出菜单 - if (editor && hasClosestByClassName(target, "protyle-wysiwyg") && - target.tagName === "SPAN" && !hasClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed")) { - const types = (target.getAttribute("data-type") || "").split(" "); - if (types.includes("inline-memo")) { - editor.protyle.toolbar.showRender(editor.protyle, target); - } - if (editor.protyle.disabled) { - return; - } - if (types.includes("block-ref")) { - refMenu(editor.protyle, target); - } else if (types.includes("file-annotation-ref")) { - fileAnnotationRefMenu(editor.protyle, target); - } else if (types.includes("tag")) { - tagMenu(editor.protyle, target); - } else if (types.includes("a")) { - linkMenu(editor.protyle, target); - } - return; - } + if (isIPhone() && globalTouchEnd(event, yDiff, time, app)) { + event.stopImmediatePropagation(); + event.preventDefault(); + return; } + const target = event.target as HTMLElement; if (!clientX || !clientY || typeof yDiff === "undefined" || target.tagName === "AUDIO" || hasClosestByClassName(target, "b3-dialog", true) ||