diff --git a/app/src/boot/globalEvent/touch.ts b/app/src/boot/globalEvent/touch.ts index 836b69b37..4ad999592 100644 --- a/app/src/boot/globalEvent/touch.ts +++ b/app/src/boot/globalEvent/touch.ts @@ -1,7 +1,7 @@ import {isIPad} 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 {fileAnnotationRefMenu, inlineMathMenu, linkMenu, refMenu, tagMenu} from "../../menus/protyle"; import {App} from "../../index"; import {Protyle} from "../../protyle"; import {getCurrentEditor} from "../../mobile/editor"; @@ -123,6 +123,11 @@ export const globalTouchEnd = (event: TouchEvent, yDiff: number, time: number, 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/menus/protyle.ts b/app/src/menus/protyle.ts index b5f6f1600..10881da2a 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -1547,6 +1547,55 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => { window.siyuan.menus.menu.element.querySelector("input").select(); }; +export const inlineMathMenu = (protyle: IProtyle, element: Element) => { + window.siyuan.menus.menu.remove(); + const nodeElement = hasClosestBlock(element); + if (!nodeElement) { + return; + } + const id = nodeElement.getAttribute("data-node-id"); + const html = nodeElement.outerHTML; + window.siyuan.menus.menu.append(new MenuItem({ + label: window.siyuan.languages.copy, + icon: "iconCopy", + click() { + writeText(protyle.lute.BlockDOM2StdMd(element.outerHTML)); + } + }).element); + if (!protyle.disabled) { + window.siyuan.menus.menu.append(new MenuItem({ + icon: "iconCut", + label: window.siyuan.languages.cut, + click() { + writeText(protyle.lute.BlockDOM2StdMd(element.outerHTML)); + + element.insertAdjacentHTML("afterend", ""); + element.remove(); + nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); + updateTransaction(protyle, id, nodeElement.outerHTML, html); + focusByWbr(nodeElement, protyle.toolbar.range); + } + }).element); + window.siyuan.menus.menu.append(new MenuItem({ + icon: "iconTrashcan", + label: window.siyuan.languages.remove, + click() { + element.insertAdjacentHTML("afterend", ""); + element.remove(); + nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); + updateTransaction(protyle, id, nodeElement.outerHTML, html); + focusByWbr(nodeElement, protyle.toolbar.range); + } + }).element); + } + const rect = element.getBoundingClientRect(); + window.siyuan.menus.menu.popup({ + x: rect.left, + y: rect.top + 26, + h: 26 + }); +} + const genImageWidthMenu = (label: string, assetElement: HTMLElement, imgElement: HTMLElement, protyle: IProtyle, id: string, nodeElement: HTMLElement, html: string) => { return { iconHTML: "", diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 41864e4cf..1b8ca5646 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -23,7 +23,7 @@ import { contentMenu, enterBack, fileAnnotationRefMenu, - imgMenu, + imgMenu, inlineMathMenu, linkMenu, refMenu, setFold, @@ -1674,6 +1674,11 @@ export class WYSIWYG { return false; } } + const inlineMathElement = hasClosestByAttribute(target, "data-type", "inline-math"); + if (inlineMathElement) { + inlineMathMenu(protyle, inlineMathElement); + return false; + } if (target.tagName === "IMG" && hasClosestByClassName(target, "img")) { imgMenu(protyle, protyle.toolbar.range, target.parentElement.parentElement, { clientX: x + 4, diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index aba28d2e1..0d19d50af 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -54,7 +54,7 @@ import { getStartEndElement, upSelect } from "./commonHotkey"; -import {fileAnnotationRefMenu, linkMenu, refMenu, setFold, tagMenu} from "../../menus/protyle"; +import {fileAnnotationRefMenu, inlineMathMenu, linkMenu, refMenu, setFold, tagMenu} from "../../menus/protyle"; import {openAttr} from "../../menus/commonMenuItem"; import {Constants} from "../../constants"; import {fetchPost} from "../../util/fetch"; @@ -594,14 +594,14 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { previousSibling.nodeType !== 3 && previousSibling.getAttribute("data-type")?.indexOf("inline-math") > -1 ) { - protyle.toolbar.showRender(protyle, previousSibling); + inlineMathMenu(protyle, previousSibling); return; } else if (!previousSibling && range.startContainer.parentElement.previousSibling && range.startContainer.parentElement.previousSibling.isSameNode(range.startContainer.parentElement.previousElementSibling) && range.startContainer.parentElement.previousElementSibling.getAttribute("data-type")?.indexOf("inline-math") > -1 ) { - protyle.toolbar.showRender(protyle, range.startContainer.parentElement.previousElementSibling); + inlineMathMenu(protyle, range.startContainer.parentElement.previousElementSibling); return; } }