diff --git a/app/src/protyle/toolbar/InlineMath.ts b/app/src/protyle/toolbar/InlineMath.ts index dc834c2b2..663a9c09e 100644 --- a/app/src/protyle/toolbar/InlineMath.ts +++ b/app/src/protyle/toolbar/InlineMath.ts @@ -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; } }