diff --git a/app/src/layout/Tab.ts b/app/src/layout/Tab.ts index 00e9403ba..ef44fc4ae 100644 --- a/app/src/layout/Tab.ts +++ b/app/src/layout/Tab.ts @@ -8,6 +8,7 @@ import {escapeHtml} from "../util/escape"; import {unicode2Emoji} from "../emoji"; import {fetchPost} from "../util/fetch"; import {showTooltip} from "../dialog/tooltip"; +import {isTouchDevice} from "../util/functions"; export class Tab { public parent: Wnd; @@ -47,8 +48,8 @@ export class Tab { let id = ""; if (this.model instanceof Editor && this.model.editor?.protyle?.block?.rootID) { id = (this.model as Editor).editor.protyle.block.rootID; - } else if (!this.model){ - const initData = JSON.parse(this.headElement.getAttribute("data-initdata")||"{}"); + } else if (!this.model) { + const initData = JSON.parse(this.headElement.getAttribute("data-initdata") || "{}"); if (initData) { id = initData.blockId; } @@ -65,6 +66,11 @@ export class Tab { } }); this.headElement.addEventListener("dragstart", (event: DragEvent & { target: HTMLElement }) => { + if (isTouchDevice()) { + event.stopPropagation(); + event.preventDefault(); + return; + } window.getSelection().removeAllRanges(); const tabElement = hasClosestByTag(event.target, "LI"); if (tabElement) { diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.ts index 7e978ee49..b17861df7 100644 --- a/app/src/layout/dock/Files.ts +++ b/app/src/layout/dock/Files.ts @@ -16,6 +16,7 @@ import {confirmDialog} from "../../dialog/confirmDialog"; import {updateHotkeyTip} from "../../protyle/util/compatibility"; import {openFileById} from "../../editor/util"; import {hasClosestByTag, hasTopClosestByTag} from "../../protyle/util/hasClosest"; +import {isTouchDevice} from "../../util/functions"; export class Files extends Model { public element: HTMLElement; @@ -268,6 +269,11 @@ export class Files extends Model { // b3-list-item--focus 样式会遮挡拖拽排序的上下线条 let focusElement: HTMLElement; this.element.addEventListener("dragstart", (event: DragEvent & { target: HTMLElement }) => { + if (isTouchDevice()) { + event.stopPropagation(); + event.preventDefault(); + return; + } window.getSelection().removeAllRanges(); focusElement = this.element.querySelector(".b3-list-item--focus"); if (focusElement) { diff --git a/app/src/util/functions.ts b/app/src/util/functions.ts index 6f3f7da91..6d036e183 100644 --- a/app/src/util/functions.ts +++ b/app/src/util/functions.ts @@ -2,6 +2,10 @@ export const isMobile = () => { return !document.getElementById("dockBottom"); }; +export const isTouchDevice = () => { + return ("ontouchstart" in window) || navigator.maxTouchPoints > 0; +}; + export const isArrayEqual = (arr1: string[], arr2: string[]) => { return arr1.length === arr2.length && arr1.every((item) => arr2.includes(item)); };