From a3c03eca073c51cf9e8d70d35369f02b2ea49249 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 26 Sep 2022 15:17:58 +0800 Subject: [PATCH] :bug: https://github.com/siyuan-note/siyuan/issues/5964 inline math --- app/src/protyle/toolbar/InlineMath.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/protyle/toolbar/InlineMath.ts b/app/src/protyle/toolbar/InlineMath.ts index e0d5840b0..c25bb8f45 100644 --- a/app/src/protyle/toolbar/InlineMath.ts +++ b/app/src/protyle/toolbar/InlineMath.ts @@ -22,7 +22,10 @@ export class InlineMath extends ToolbarItem { } 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"]'); + const previousSibling = hasPreviousSibling(range.startContainer.childNodes[range.startOffset]) as HTMLElement; + if (previousSibling && previousSibling.getAttribute("data-type").indexOf("inline-math") > -1) { + mathElement = previousSibling + } } if (!mathElement && range.startOffset === range.startContainer.textContent.length && range.startContainer.nodeType === 3) { let isMath = true; @@ -38,6 +41,11 @@ export class InlineMath extends ToolbarItem { 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) { + mathElement = previousSibling; + } } } }