🎨 数学公式不允许备注

This commit is contained in:
Vanessa 2022-09-20 20:10:42 +08:00
parent 656a6f966e
commit d4c8376bb5
3 changed files with 43 additions and 10 deletions

View file

@ -1,7 +1,7 @@
import {ToolbarItem} from "./ToolbarItem";
import * as dayjs from "dayjs";
import {updateTransaction} from "../wysiwyg/transaction";
import {hasClosestBlock} from "../util/hasClosest";
import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest";
import {hasNextSibling, hasPreviousSibling} from "../wysiwyg/getBlock";
import {mathRender} from "../markdown/mathRender";
import {fixTableRange} from "../util/selection";
@ -20,6 +20,14 @@ export class InlineMath extends ToolbarItem {
if (!nodeElement) {
return;
}
let mathElement = hasClosestByAttribute(range.startContainer, "data-type", "inline-math") as Element;
if (!mathElement && range.startContainer.nodeType !== 3) {
mathElement = (range.startContainer as HTMLElement).querySelector('[data-type="inline-math"]');
}
if (mathElement) {
protyle.toolbar.showRender(protyle, mathElement);
return;
}
fixTableRange(range);
if (!["DIV", "TD", "TH", "TR"].includes(range.startContainer.parentElement.tagName) && range.startOffset === 0 && !hasPreviousSibling(range.startContainer)) {
range.setStartBefore(range.startContainer.parentElement);