An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 为空数学公式关闭,光标位置错误
Vanessac35a9fde6bc5
diff --git a/app/src/protyle/toolbar/InlineMath.ts b/app/src/protyle/toolbar/InlineMath.tsindex 2f223ced43..c6af3aab10 100644--- a/app/src/protyle/toolbar/InlineMath.ts+++ b/app/src/protyle/toolbar/InlineMath.ts@@ -4,7 +4,7 @@ import {updateTransaction} from "../wysiwyg/transaction";import {hasClosestBlock, hasClosestByAttribute} from "../util/hasClosest";import {hasNextSibling, hasPreviousSibling} from "../wysiwyg/getBlock";import {mathRender} from "../markdown/mathRender";-import {fixTableRange} from "../util/selection";+import {fixTableRange, focusByRange} from "../util/selection";export class InlineMath extends ToolbarItem {public element: HTMLElement;@@ -50,11 +50,15 @@ export class InlineMath extends ToolbarItem {range.insertNode(newElement);mathRender(newElement);if (rangeString.trim() === "") {- protyle.toolbar.showRender(protyle, newElement);+ protyle.toolbar.showRender(protyle, newElement, undefined, html);+ } else {+ range.setStartAfter(newElement);+ range.collapse(true);+ focusByRange(range)+ nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));+ updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);+ wbrElement.remove();}- nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));- updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);- wbrElement.remove();});}}diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.tsindex 314e99cb4f..3435e5db26 100644--- a/app/src/protyle/toolbar/index.ts+++ b/app/src/protyle/toolbar/index.ts@@ -876,7 +876,7 @@ export class Toolbar {if (!renderElement.parentElement) {return;}- let inlineMemoLastNode: Element;+ let inlineLastNode: Element;if (types.includes("NodeHTMLBlock")) {renderElement.querySelector("protyle-html").setAttribute("data-content", Lute.EscapeHTMLStr(textElement.value));} else if (isInlineMemo) {@@ -903,12 +903,22 @@ export class Toolbar {item.removeAttribute("data-inline-memo-content");}if (index === inlineMemoElements.length - 1) {- inlineMemoLastNode = item;+ inlineLastNode = item;}} else {item.setAttribute("data-inline-memo-content", Lute.EscapeHTMLStr(textElement.value));}});+ } else if (types.includes("inline-math")) {+ // 行内数学公式不允许换行 https://github.com/siyuan-note/siyuan/issues/2187+ if (textElement.value) {+ renderElement.setAttribute("data-content", Lute.EscapeHTMLStr(textElement.value.replace(/\n/g, "")));+ renderElement.removeAttribute("data-render");+ processRender(renderElement);+ } else {+ inlineLastNode = renderElement;+ renderElement.outerHTML = "<wbr>"+ }} else {renderElement.setAttribute("data-content", Lute.EscapeHTMLStr(textElement.value));renderElement.removeAttribute("data-render");@@ -919,10 +929,11 @@ export class Toolbar {}}+ // 光标定位if (renderElement.tagName === "SPAN") {- if (inlineMemoLastNode) {- if (inlineMemoLastNode.parentElement) {- this.range.setStartAfter(inlineMemoLastNode);+ if (inlineLastNode) {+ if (inlineLastNode.parentElement) {+ this.range.setStartAfter(inlineLastNode);this.range.collapse(true);focusByRange(this.range);} else {@@ -936,10 +947,7 @@ export class Toolbar {} else {focusSideBlock(renderElement);}- if (types.includes("inline-math")) {- // 行内数学公式不允许换行 https://github.com/siyuan-note/siyuan/issues/2187- renderElement.setAttribute("data-content", renderElement.getAttribute("data-content").replace(/\n/g, ""));- }+nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));const newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);// HTML 块中包含多个 <pre> 时只能保存第一个 https://github.com/siyuan-note/siyuan/issues/5732