mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 10:00:13 +01:00
This commit is contained in:
parent
45056634bd
commit
a90402845b
4 changed files with 64 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import {isIPad} from "../../protyle/util/compatibility";
|
import {isIPad} from "../../protyle/util/compatibility";
|
||||||
import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByTag} from "../../protyle/util/hasClosest";
|
import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByTag} from "../../protyle/util/hasClosest";
|
||||||
import {initFileMenu, initNavigationMenu} from "../../menus/navigation";
|
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 {App} from "../../index";
|
||||||
import {Protyle} from "../../protyle";
|
import {Protyle} from "../../protyle";
|
||||||
import {getCurrentEditor} from "../../mobile/editor";
|
import {getCurrentEditor} from "../../mobile/editor";
|
||||||
|
|
@ -123,6 +123,11 @@ export const globalTouchEnd = (event: TouchEvent, yDiff: number, time: number, a
|
||||||
linkMenu(editor.protyle, target);
|
linkMenu(editor.protyle, target);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const inlineMathElement = hasClosestByAttribute(target, "data-type", "inline-math");
|
||||||
|
if (inlineMathElement) {
|
||||||
|
inlineMathMenu(editor.protyle, inlineMathElement);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -1547,6 +1547,55 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => {
|
||||||
window.siyuan.menus.menu.element.querySelector("input").select();
|
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", "<wbr>");
|
||||||
|
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", "<wbr>");
|
||||||
|
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) => {
|
const genImageWidthMenu = (label: string, assetElement: HTMLElement, imgElement: HTMLElement, protyle: IProtyle, id: string, nodeElement: HTMLElement, html: string) => {
|
||||||
return {
|
return {
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import {
|
||||||
contentMenu,
|
contentMenu,
|
||||||
enterBack,
|
enterBack,
|
||||||
fileAnnotationRefMenu,
|
fileAnnotationRefMenu,
|
||||||
imgMenu,
|
imgMenu, inlineMathMenu,
|
||||||
linkMenu,
|
linkMenu,
|
||||||
refMenu,
|
refMenu,
|
||||||
setFold,
|
setFold,
|
||||||
|
|
@ -1674,6 +1674,11 @@ export class WYSIWYG {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const inlineMathElement = hasClosestByAttribute(target, "data-type", "inline-math");
|
||||||
|
if (inlineMathElement) {
|
||||||
|
inlineMathMenu(protyle, inlineMathElement);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
if (target.tagName === "IMG" && hasClosestByClassName(target, "img")) {
|
||||||
imgMenu(protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
imgMenu(protyle, protyle.toolbar.range, target.parentElement.parentElement, {
|
||||||
clientX: x + 4,
|
clientX: x + 4,
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ import {
|
||||||
getStartEndElement,
|
getStartEndElement,
|
||||||
upSelect
|
upSelect
|
||||||
} from "./commonHotkey";
|
} 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 {openAttr} from "../../menus/commonMenuItem";
|
||||||
import {Constants} from "../../constants";
|
import {Constants} from "../../constants";
|
||||||
import {fetchPost} from "../../util/fetch";
|
import {fetchPost} from "../../util/fetch";
|
||||||
|
|
@ -594,14 +594,14 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
previousSibling.nodeType !== 3 &&
|
previousSibling.nodeType !== 3 &&
|
||||||
previousSibling.getAttribute("data-type")?.indexOf("inline-math") > -1
|
previousSibling.getAttribute("data-type")?.indexOf("inline-math") > -1
|
||||||
) {
|
) {
|
||||||
protyle.toolbar.showRender(protyle, previousSibling);
|
inlineMathMenu(protyle, previousSibling);
|
||||||
return;
|
return;
|
||||||
} else if (!previousSibling &&
|
} else if (!previousSibling &&
|
||||||
range.startContainer.parentElement.previousSibling &&
|
range.startContainer.parentElement.previousSibling &&
|
||||||
range.startContainer.parentElement.previousSibling.isSameNode(range.startContainer.parentElement.previousElementSibling) &&
|
range.startContainer.parentElement.previousSibling.isSameNode(range.startContainer.parentElement.previousElementSibling) &&
|
||||||
range.startContainer.parentElement.previousElementSibling.getAttribute("data-type")?.indexOf("inline-math") > -1
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue