From 56ee07f70318f9c152b0406be3ecf14cd2284ca2 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 30 Sep 2024 12:10:53 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/12637 --- app/src/protyle/wysiwyg/enter.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/protyle/wysiwyg/enter.ts b/app/src/protyle/wysiwyg/enter.ts index 692cfc739..4e9ea6950 100644 --- a/app/src/protyle/wysiwyg/enter.ts +++ b/app/src/protyle/wysiwyg/enter.ts @@ -17,7 +17,7 @@ import {isIPad, setStorageVal} from "../util/compatibility"; import {mathRender} from "../render/mathRender"; import {isMobile} from "../../util/functions"; import {processRender} from "../util/processCode"; -import {hasClosestByClassName} from "../util/hasClosest"; +import {hasClosestByAttribute, hasClosestByClassName} from "../util/hasClosest"; export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle) => { if (hasClosestByClassName(blockElement, "protyle-wysiwyg__embed")) { @@ -198,7 +198,19 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle range.insertNode(wbrElement); const html = blockElement.outerHTML; wbrElement.remove(); + if (range.toString() !== "") { + // 选中数学公式后回车取消选中 https://github.com/siyuan-note/siyuan/issues/12637#issuecomment-2381106949 + const mathElement = hasClosestByAttribute(range.startContainer, "data-type", "inline-math") + if (mathElement) { + const nextSibling = hasNextSibling(mathElement); + if (nextSibling) { + range = getSelection().getRangeAt(0) + range.setEnd(nextSibling, nextSibling.textContent.startsWith(Constants.ZWSP) ? 1 : 0); + range.collapse(false); + } + return true; + } range.extractContents(); } if (editableElement.lastChild) {