Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: fix https://github.com/siyuan-note/siyuan/issues/6643

Vanessaabc37e86d865
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 5a5f41a08c..5d579ad4f2 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") {
+ 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.setStartBefore(lastNewNode);
+ }
const mathNextSibling = hasNextSibling(lastNewNode);
- if (mathNextSibling) { // https://github.com/siyuan-note/siyuan/issues/6065
- this.range.setStart(mathNextSibling, 0);
+ if (mathNextSibling && mathNextSibling.nodeType === 3) { // https://github.com/siyuan-note/siyuan/issues/6065
+ this.range.setEnd(mathNextSibling, 0);
} else {
- this.range.setStartAfter(lastNewNode);
+ this.range.setEndAfter(lastNewNode);
}
- this.range.collapse(true);
} else {
if (lastNewNode.lastChild) {
if (lastNewNode.lastChild.textContent === Constants.ZWSP) {