Skip to content

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

:bug: Preserve IME input after exiting inline math editing https://github.com/siyuan-note/siyuan/issues/16977

Daniel840412ee3655
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index 782e14469d..9d354ae9ef 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -1861,6 +1861,16 @@ export class Toolbar {
} else if (renderElement.parentElement) {
if (focusBeforeRender) {
this.range.setStartBefore(renderElement);
+ } else if (types.includes("inline-math")) {
+ // 在公式外的文本节点中恢复光标,为输入法提供可编辑的组合输入位置。
+ let textNode = renderElement.nextSibling as Text;
+ if (!textNode || textNode.nodeType !== Node.TEXT_NODE) {
+ textNode = document.createTextNode(Constants.ZWSP);
+ renderElement.after(textNode);
+ } else if (!textNode.data.startsWith(Constants.ZWSP)) {
+ textNode.insertData(0, Constants.ZWSP);
+ }
+ this.range.setStart(textNode, 1);
} else {
this.range.setStartAfter(renderElement);
}