From abc37e86d8658cef3f368bbc5db54191541f1247 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 18 Nov 2022 16:03:39 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/6643 --- app/src/protyle/toolbar/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 5a5f41a08..5d579ad4f 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -610,14 +610,19 @@ export class Toolbar { this.range.setEnd(nextElement.lastChild, nextIndex); } else if (newNodes.length > 0) { const lastNewNode = newNodes[newNodes.length - 1]; - if (lastNewNode.nodeType !== 3 && (lastNewNode as HTMLElement).getAttribute("data-type") === "inline-math") { - const mathNextSibling = hasNextSibling(lastNewNode); - if (mathNextSibling) { // https://github.com/siyuan-note/siyuan/issues/6065 - this.range.setStart(mathNextSibling, 0); + if (lastNewNode.nodeType !== 3 && (lastNewNode as HTMLElement).getAttribute("data-type").indexOf("inline-math") > -1) { + const mathPreviousSibling = hasPreviousSibling(lastNewNode); + if (mathPreviousSibling && mathPreviousSibling.nodeType === 3) { + this.range.setStart(mathPreviousSibling, mathPreviousSibling.textContent.length); } else { - this.range.setStartAfter(lastNewNode); + this.range.setStartBefore(lastNewNode); + } + const mathNextSibling = hasNextSibling(lastNewNode); + if (mathNextSibling && mathNextSibling.nodeType === 3) { // https://github.com/siyuan-note/siyuan/issues/6065 + this.range.setEnd(mathNextSibling, 0); + } else { + this.range.setEndAfter(lastNewNode); } - this.range.collapse(true); } else { if (lastNewNode.lastChild) { if (lastNewNode.lastChild.textContent === Constants.ZWSP) {