From c03b24fc01daae1e8a6b726d1a1c4eba403bbe61 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 28 Sep 2022 21:20:47 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/6007 --- app/src/protyle/toolbar/InlineMath.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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; } }