This commit is contained in:
Vanessa 2022-09-28 21:20:47 +08:00
parent 91edc8e254
commit c03b24fc01

View file

@ -25,21 +25,24 @@ export class InlineMath extends ToolbarItem {
}
if (!mathElement && range.startOffset === range.startContainer.textContent.length && range.startContainer.nodeType === 3) {
let isMath = true;
let hasMath = false;
// https://github.com/siyuan-note/siyuan/issues/6007
range.cloneContents().childNodes.forEach((item: HTMLElement) => {
if ((item.nodeType !== 3 && item.getAttribute("data-type").indexOf("inline-math") > -1) ||
(item.nodeType == 3 && item.textContent === "")) {
// 是否仅选中数学公式
hasMath = true;
} else {
isMath = false;
}
});
if (isMath) {
if (isMath && hasMath) {
const nextSibling = hasNextSibling(range.startContainer) as HTMLElement;
if (nextSibling && nextSibling.nodeType !== 3 && nextSibling.getAttribute("data-type").indexOf("inline-math") > -1) {
mathElement = nextSibling;
} else {
const previousSibling = hasPreviousSibling(range.startContainer) as HTMLElement;
if (previousSibling && previousSibling.nodeType !== 3 && previousSibling.getAttribute("data-type").indexOf("inline-math") > -1) {
if (range.startOffset === 0 && previousSibling && previousSibling.nodeType !== 3 && previousSibling.getAttribute("data-type").indexOf("inline-math") > -1) {
mathElement = previousSibling;
}
}