Skip to content

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

:bug: Restore inline math insertion from table cell slash menus https://github.com/siyuan-note/siyuan/issues/19524

Danielf9b4bd5b5dc9
diff --git a/app/src/protyle/hint/builtinSlash.ts b/app/src/protyle/hint/builtinSlash.ts
new file mode 100644
index 0000000000..32d1e1c1ff
--- /dev/null
+++ b/app/src/protyle/hint/builtinSlash.ts
@@ -0,0 +1,11 @@
+type TSlashHint = (key: string, protyle: IProtyle, source: THintSource) => IHintData[];
+
+const builtinSlashHints = new WeakSet<TSlashHint>();
+
+// 标记内置斜杠菜单及其过滤包装,保留候选项的命令语义。
+export const registerBuiltinSlashHint = <T extends TSlashHint>(hint: T): T => {
+ builtinSlashHints.add(hint);
+ return hint;
+};
+
+export const isBuiltinSlashHint = (hint: TSlashHint) => builtinSlashHints.has(hint);
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts
index 4ac89c9029..54113b05d0 100644
--- a/app/src/protyle/hint/extend.ts
+++ b/app/src/protyle/hint/extend.ts
@@ -1,4 +1,5 @@
import {fetchPost} from "../../util/fetch";
+import {registerBuiltinSlashHint} from "./builtinSlash";
import {insertHTML} from "../util/insertHTML";
import {TABLE_CELL_SLASH_IDS} from "../util/tableCellRichMenu";
import {getIconByType} from "../../editor/getIcon";
@@ -424,7 +425,7 @@ export const getBuiltinSlashMenuItems = (protyle: IProtyle): IHintData[] => {
}];
};
-export const hintSlash = (key: string, protyle: IProtyle, sourceOrHideConfiguredCreate: THintSource | boolean = false) => {
+export const hintSlash = registerBuiltinSlashHint((key: string, protyle: IProtyle, sourceOrHideConfiguredCreate: THintSource | boolean = false) => {
const enabled = isEntryVisible(SLASH_MENU_ROOT_PATH);
if (!enabled) {
return [];
@@ -475,7 +476,7 @@ export const hintSlash = (key: string, protyle: IProtyle, sourceOrHideConfigured
order: getEntryOrder(SLASH_MENU_ROOT_PATH),
visible: (entryKey) => isEntryVisible(getSlashMenuEntryPath(entryKey)),
});
-};
+});
export const hintTag = (key: string, protyle: IProtyle): IHintData[] => {
protyle.hint.genLoading(protyle);
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index 039cf90a99..fb500ba1c2 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -1,4 +1,5 @@
import {Constants} from "../../constants";
+import {isBuiltinSlashHint} from "./builtinSlash";
import {
hasClosestBlock,
hasClosestByAttribute,
@@ -928,7 +929,7 @@ ${genHintItemHTML(item)}
} else if (this.splitChar === "/" || this.splitChar === "、") {
// 精简模式的自定义候选按文本插入,内置候选执行命令;块引用保留本地事务和后续提示。
if (protyle.lite && (Constants.BLOCK_HINT_KEYS.includes(value) ||
- protyle.options.hint.extend.find((item) => item.key === "/" && item.hint)?.hint !== hintSlash)) {
+ !isBuiltinSlashHint(protyle.options.hint.extend.find((item) => item.key === "/" && item.hint)?.hint))) {
insertHTML(value, protyle, false, false, false, undefined, undoContext);
if (Constants.BLOCK_HINT_KEYS.includes(value)) {
this.enableExtend = true;
diff --git a/app/src/protyle/render/av/richTextEditor.ts b/app/src/protyle/render/av/richTextEditor.ts
index 3e6088a756..71d599624f 100644
--- a/app/src/protyle/render/av/richTextEditor.ts
+++ b/app/src/protyle/render/av/richTextEditor.ts
@@ -2,6 +2,7 @@ import {escapeHtml} from "../../../util/escape";
import {isMobile} from "../../../util/functions";
import {callMobileAppShowKeyboard} from "../../../mobile/util/mobileAppUtil";
import {hintRef, hintSlash} from "../../hint/extend";
+import {registerBuiltinSlashHint} from "../../hint/builtinSlash";
import {mountProtyleLiteFragment} from "../../lite/fragmentEditor";
import {getDefaultToolbar} from "../../toolbar/defaults";
import {highlightRender} from "../highlightRender";
@@ -78,10 +79,10 @@ const hintAVRef = (key: string, protyle: IProtyle, source: THintSource) => {
return hintRef(key, protyle, source);
};
-const hintAVSlash = (key: string, protyle: IProtyle, source: THintSource) => {
+const hintAVSlash = registerBuiltinSlashHint((key: string, protyle: IProtyle, source: THintSource) => {
prepareHint(protyle);
return hintSlash(key, protyle, source).filter((item) => item.id && SAFE_SLASH_IDS.has(item.id));
-};
+});
const setPanelPosition = (panelElement: HTMLElement, anchorElement: HTMLElement) => {
if (isMobile()) {
diff --git a/app/src/protyle/render/tableCellRichEditor.ts b/app/src/protyle/render/tableCellRichEditor.ts
index 47d0ee12d4..3d76da2800 100644
--- a/app/src/protyle/render/tableCellRichEditor.ts
+++ b/app/src/protyle/render/tableCellRichEditor.ts
@@ -1,6 +1,7 @@
import {isMobile} from "../../util/functions";
import {showMessage} from "../../dialog/message";
import {hintRef, hintSlash} from "../hint/extend";
+import {registerBuiltinSlashHint} from "../hint/builtinSlash";
import {mountProtyleLiteFragment} from "../lite/fragmentEditor";
import {getDefaultToolbar} from "../toolbar/defaults";
import {hideElements} from "../ui/hideElements";
@@ -144,8 +145,8 @@ export const openTableCellRichEditor = (owner: IProtyle, cell: HTMLTableCellElem
event.stopPropagation();
}));
const toolbar = getDefaultToolbar(isMobile()).filter(item => typeof item === "string" ? item !== "ai" : item.name !== "ai");
- const safeSlash = (key: string, protyle: IProtyle, hintSource: THintSource) =>
- hintSlash(key, protyle, hintSource).filter(item => TABLE_CELL_SLASH_IDS.has(item.id));
+ const safeSlash = registerBuiltinSlashHint((key: string, protyle: IProtyle, hintSource: THintSource) =>
+ hintSlash(key, protyle, hintSource).filter(item => TABLE_CELL_SLASH_IDS.has(item.id)));
const hint: IProtyleOptions["hint"] = {
extend: [{key: "((", hint: hintRef}, {key: "【【", hint: hintRef}, {key: "((", hint: hintRef},
{key: "[[", hint: hintRef}, {key: "/", hint: safeSlash}, {key: "、", hint: safeSlash}],