🎨 数学公式不允许备注
This commit is contained in:
parent
656a6f966e
commit
d4c8376bb5
3 changed files with 43 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -43,15 +43,17 @@ export class InlineMemo extends ToolbarItem {
|
|||
const contents = range.extractContents();
|
||||
contents.childNodes.forEach((item: HTMLElement) => {
|
||||
if (item.nodeType === 3) {
|
||||
const inlineElement = document.createElement("span");
|
||||
inlineElement.setAttribute("data-type", "inline-memo");
|
||||
inlineElement.textContent = item.textContent;
|
||||
newNodes.push(inlineElement);
|
||||
if (item.textContent) {
|
||||
const inlineElement = document.createElement("span");
|
||||
inlineElement.setAttribute("data-type", "inline-memo");
|
||||
inlineElement.textContent = item.textContent;
|
||||
newNodes.push(inlineElement);
|
||||
}
|
||||
} else {
|
||||
let types = (item.getAttribute("data-type") || "").split(" ");
|
||||
types.push("inline-memo");
|
||||
types = [...new Set(types)];
|
||||
if (item.tagName !== "BR" && item.tagName !== "WBR") {
|
||||
if (item.tagName !== "BR" && item.tagName !== "WBR" && !types.includes("inline-math")) {
|
||||
item.setAttribute("data-type", types.join(" "));
|
||||
newNodes.push(item);
|
||||
} else if (item.tagName !== "WBR") {
|
||||
|
@ -76,10 +78,17 @@ export class InlineMemo extends ToolbarItem {
|
|||
} else {
|
||||
range.insertNode(newNodes[i]);
|
||||
range.collapse(false);
|
||||
// 数学公式不允许备注
|
||||
if (currentNewNode.nodeType !== 3 && (currentNewNode.getAttribute("data-type") || "").indexOf("inline-math") > -1) {
|
||||
newNodes.splice(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
range.setStart(newNodes[0].firstChild, 0);
|
||||
protyle.toolbar.showRender(protyle, newNodes[0], newNodes, oldHTML);
|
||||
if (newNodes[0]) {
|
||||
range.setStart(newNodes[0].firstChild, 0);
|
||||
protyle.toolbar.showRender(protyle, newNodes[0], newNodes, oldHTML);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -876,6 +876,7 @@ export class Toolbar {
|
|||
if (!renderElement.parentElement) {
|
||||
return;
|
||||
}
|
||||
let inlineMemoLastNode: Element;
|
||||
if (types.includes("NodeHTMLBlock")) {
|
||||
renderElement.querySelector("protyle-html").setAttribute("data-content", Lute.EscapeHTMLStr(textElement.value));
|
||||
} else if (isInlineMemo) {
|
||||
|
@ -890,7 +891,7 @@ export class Toolbar {
|
|||
// https://github.com/siyuan-note/insider/issues/1046
|
||||
const currentTypes = item.getAttribute("data-type").split(" ");
|
||||
if (currentTypes.length === 1 && currentTypes[0] === "inline-memo") {
|
||||
item.outerHTML = item.innerHTML;
|
||||
item.outerHTML = item.innerHTML + (index === inlineMemoElements.length - 1 ? "<wbr>" : "");
|
||||
} else {
|
||||
currentTypes.find((typeItem, index) => {
|
||||
if (typeItem === "inline-memo") {
|
||||
|
@ -901,6 +902,9 @@ export class Toolbar {
|
|||
item.setAttribute("data-type", currentTypes.join(" "));
|
||||
item.removeAttribute("data-inline-memo-content");
|
||||
}
|
||||
if (index === inlineMemoElements.length - 1) {
|
||||
inlineMemoLastNode = item;
|
||||
}
|
||||
} else {
|
||||
item.setAttribute("data-inline-memo-content", Lute.EscapeHTMLStr(textElement.value));
|
||||
}
|
||||
|
@ -916,7 +920,19 @@ export class Toolbar {
|
|||
}
|
||||
|
||||
if (renderElement.tagName === "SPAN") {
|
||||
focusByRange(this.range);
|
||||
if (inlineMemoLastNode) {
|
||||
if (inlineMemoLastNode.parentElement) {
|
||||
this.range.setStartAfter(inlineMemoLastNode);
|
||||
this.range.collapse(true);
|
||||
focusByRange(this.range);
|
||||
} else {
|
||||
focusByWbr(nodeElement, this.range)
|
||||
}
|
||||
} else if (renderElement.parentElement) {
|
||||
this.range.setStartAfter(renderElement);
|
||||
this.range.collapse(true);
|
||||
focusByRange(this.range);
|
||||
}
|
||||
} else {
|
||||
focusSideBlock(renderElement);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue