An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Enter restricted cell editing after creating tables https://github.com/siyuan-note/siyuan/issues/19188
Daniel1f9cda3bbf06
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.tsindex c0a3d43bb0..65914c794d 100644--- a/app/src/protyle/hint/extend.ts+++ b/app/src/protyle/hint/extend.ts@@ -1,5 +1,6 @@import {fetchPost} from "../../util/fetch";import {insertHTML} from "../util/insertHTML";+import {TABLE_CELL_SLASH_IDS} from "../util/tableCellRichMenu";import {getIconByType} from "../../editor/getIcon";import {isDisabledFeature, updateHotkeyTip} from "../util/compatibility";import {blockRender} from "../render/blockRender";@@ -454,9 +455,15 @@ export const hintSlash = (key: string, protyle: IProtyle, sourceOrHideConfiguredallList.pop();}refreshSlashMenuCatalog(areProtylePluginExtensionsEnabled(protyle) ? protyle.app.plugins : []);+ const selection = getSelection();+ const focus = selection?.focusNode;+ const focusElement = focus instanceof Element ? focus : focus?.parentElement;+ const cell = focusElement?.closest("td, th");+ const inTableCell = cell && cell.closest(".protyle-wysiwyg") === protyle.wysiwyg.element;return resolveSlashMenuItems(allList.filter((item) => {const builtinStyleID = slashBuiltinStyleIDs[item.entryKey];- return getEntryCatalogNode(getSlashMenuEntryPath(item.entryKey)) &&+ return (!inTableCell || TABLE_CELL_SLASH_IDS.has(item.id)) &&+ getEntryCatalogNode(getSlashMenuEntryPath(item.entryKey)) &&(!builtinStyleID || isBuiltinInlineStyleVisible("style1", builtinStyleID));}), {enabled,diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.tsindex 08c8b1b3c0..a02399eb7b 100644--- a/app/src/protyle/hint/index.ts+++ b/app/src/protyle/hint/index.ts@@ -1197,6 +1197,19 @@ ${genHintItemHTML(item)}}}}+ // 新建表格后直接接管当前单元格,后续输入与鼠标点击进入编辑使用相同的限制。+ const selection = getSelection();+ const focus = selection?.focusNode;+ const focusElement = focus instanceof Element ? focus : focus?.parentElement;+ const cell = focusElement?.closest<HTMLTableCellElement>("td, th");+ if (cell && cell.closest(".protyle-wysiwyg") === protyle.wysiwyg.element &&+ cell.contains(selection.anchorNode)) {+ void import("../render/tableCellRichEditor").then(module => {+ if (cell.contains(getSelection()?.focusNode)) {+ module.openTableCellRichEditor(protyle, cell);+ }+ });+ }}public select(event: KeyboardEvent, protyle: IProtyle) {diff --git a/app/src/protyle/render/tableCellRichEditor.ts b/app/src/protyle/render/tableCellRichEditor.tsindex 8728b77efc..4a6cc84fb7 100644--- a/app/src/protyle/render/tableCellRichEditor.ts+++ b/app/src/protyle/render/tableCellRichEditor.ts@@ -14,12 +14,8 @@ import {TABLE_CELL_RICH_ATTRIBUTE} from "../util/tableCellRichValue";import {focusByOffset, getSelectionOffset} from "../util/selection";import {fixTable} from "../util/table";import {updateTableCellContentLayout} from "../util/tableCellRich";+import {TABLE_CELL_SLASH_IDS} from "../util/tableCellRichMenu";-const SAFE_SLASH_IDS = new Set([- "ref", "heading1", "heading2", "heading3", "heading4", "heading5", "heading6", "list", "orderedList", "check",- "quote", "code", "math", "link", "bold", "italic", "underline", "strike", "mark", "sup", "sub", "inlineCode",- "kbd", "tag", "inlineMath",-]);let activeEditor: {cell: Element, finish: () => void} | undefined;export const applyTableCellRichInlineMark = (owner: IProtyle, cells: HTMLTableCellElement[], type: string,@@ -119,7 +115,7 @@ export const openTableCellRichEditor = (owner: IProtyle, cell: HTMLTableCellElem}));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 => SAFE_SLASH_IDS.has(item.id));+ 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}],diff --git a/app/src/protyle/util/tableCellRichMenu.ts b/app/src/protyle/util/tableCellRichMenu.tsnew file mode 100644index 0000000000..14cfd10ab4--- /dev/null+++ b/app/src/protyle/util/tableCellRichMenu.ts@@ -0,0 +1,5 @@+export const TABLE_CELL_SLASH_IDS = new Set([+ "ref", "heading1", "heading2", "heading3", "heading4", "heading5", "heading6", "list", "orderedList", "check",+ "quote", "code", "math", "link", "bold", "italic", "underline", "strike", "mark", "sup", "sub", "inlineCode",+ "kbd", "tag", "inlineMath",+]);