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: Preserve empty formulas and mobile block actions in rich table cells
Daniel6b28764d88c8
diff --git a/app/src/mobile/util/keyboardToolbar.ts b/app/src/mobile/util/keyboardToolbar.tsindex 81f112c6e0..c4f0ed3c28 100644--- a/app/src/mobile/util/keyboardToolbar.ts+++ b/app/src/mobile/util/keyboardToolbar.ts@@ -82,6 +82,9 @@ import {getEntryOrder, isEntryVisible} from "../../config/entryVisibility/runtimimport {TOOLBAR_ENTRY_ROOT_PATH} from "../../protyle/toolbar/defaults";import {getKeyboardPanelHeight} from "./keyboardPanelHeight";import {mountLiteSlashMenu} from "./liteSlashMenu";+import {getTableCellRichContext} from "../../protyle/util/tableCellRichContext";+import {insertEmptyBlock} from "../../block/util";+import {getIconByType} from "../../editor/getIcon";const getCurrentEditor = () => getMobileToolbarProtyle()?.getInstance() || getDocumentEditor();let toolbarProtyle: IProtyle;@@ -948,6 +951,14 @@ const renderKeyboardToolbar = () => {return;}+ const blockButton = document.querySelector<HTMLElement>('#keyboardToolbar [data-type="block"]');+ const blockType = nodeElement.getAttribute("data-type");+ blockButton.querySelector("use").setAttribute("xlink:href",+ `#${getIconByType(blockType, nodeElement.getAttribute("data-subtype")) || "iconParagraph"}`);+ blockButton.setAttribute("aria-label", blockType === "NodeCodeBlock" ? window.siyuan.languages.code :+ blockType === "NodeMathBlock" ? window.siyuan.languages.math :+ blockType === "NodeParagraph" ? window.siyuan.languages.paragraph : window.siyuan.languages.contentBlock);+const selectText = stripSemanticMarkersFromRangeText(range).split(Constants.ZWSP).join("");const startCellElement = hasClosestByTag(range.startContainer, "TD") ||hasClosestByTag(range.startContainer, "TH");@@ -1078,7 +1089,8 @@ const showKeyboardToolbarElement = () => {toolbarProtyle = protyle;updateMobilePluginToolbar(protyle);}- toolbarElement.querySelector('[data-type="block"]').classList.toggle("fn__none", !protyle.gutter);+ toolbarElement.querySelector('[data-type="block"]').classList.toggle("fn__none",+ !protyle.gutter && !getTableCellRichContext(protyle));if (!toolbarElement.classList.contains("fn__none")) {return;}@@ -1826,6 +1838,27 @@ export const initKeyboardToolbar = () => {protyle.toolbar.range = range;keyboardPanelClosing = false;hideKeyboardToolbarUtil();+ if (!protyle.gutter && getTableCellRichContext(protyle)) {+ const {MenuItem} = await import("../../menus/Menu");+ if (!nodeElement.isConnected || protyle.disabled || !getTableCellRichContext(protyle)) {+ return;+ }+ window.siyuan.menus.menu.remove();+ window.siyuan.menus.menu.append(new MenuItem({+ id: "insertBefore",+ icon: "iconBefore",+ label: window.siyuan.languages.insertBefore,+ click: () => insertEmptyBlock(protyle, "beforebegin", nodeElement),+ }).element);+ window.siyuan.menus.menu.append(new MenuItem({+ id: "insertAfter",+ icon: "iconAfter",+ label: window.siyuan.languages.insertAfter,+ click: () => insertEmptyBlock(protyle, "afterend", nodeElement),+ }).element);+ window.siyuan.menus.menu.fullscreen("all", restoreMenuKeyboard);+ return;+ }protyle.gutter?.renderMenu(protyle, nodeElement);window.siyuan.menus.menu.fullscreen("all", restoreMenuKeyboard);return;diff --git a/kernel/model/table_cell_rich_fts5_test.go b/kernel/model/table_cell_rich_fts5_test.goindex a77283eddd..7b791e963b 100644--- a/kernel/model/table_cell_rich_fts5_test.go+++ b/kernel/model/table_cell_rich_fts5_test.go@@ -59,3 +59,56 @@ func TestTableCellRichCodeSettingsTransactions(t *testing.T) {}}}++func TestTableCellRichEmptyMathBlockTransaction(t *testing.T) {+ fixture := setupStructureTransactionTest(t)+ setupFoldTransactionDatabase(t, fixture)+ tree, err := LoadTreeByBlockID(fixture.sourceID)+ if err != nil {+ t.Fatal(err)+ }+ luteEngine := util.NewLute()+ makeTable := func(source string) *parse.Tree {+ result := parse.Parse("", []byte("| Header |\n| --- |\n| cell |"), luteEngine.ParseOptions)+ result.Root.FirstChild.LastChild.FirstChild.TableCellRich = &ast.TableCellRich{+ Spec: 1, Format: "kramdown", Content: source,+ }+ if err := treenode.RefreshTableCellRichProjection(result.Root); err != nil {+ t.Fatal(err)+ }+ return result+ }+ initial := makeTable("- list")+ table := initial.Root.FirstChild+ table.ID = ast.NewNodeID()+ table.SetIALAttr("id", table.ID)+ tree.Root.AppendChild(table)+ if _, err = filesys.WriteTree(tree); err != nil {+ t.Fatal(err)+ }+ treenode.UpsertBlockTree(tree)+ for _, source := range []string{+ "- list\n\n$$\n\n$$",+ "- list\n\n$$\n\n$$\n\nnext",+ "- list\n\n```\n\n```",+ "- list\n\n```\n\n```\n\nnext",+ "- list\n\n$$\nx^2\n$$",+ } {+ updated := makeTable(source)+ updated.Root.FirstChild.ID = table.ID+ updated.Root.FirstChild.SetIALAttr("id", table.ID)+ tx := &Transaction{DoOperations: []*Operation{{Action: "update", ID: table.ID,+ Data: luteEngine.Tree2BlockDOM(updated, luteEngine.RenderOptions, luteEngine.ParseOptions)}}}+ if err = PerformTxSync(tx); err != nil {+ t.Fatalf("updating rich table cell with %q failed: %s", source, err)+ }+ restored, err := LoadTreeByBlockID(table.ID)+ if err != nil {+ t.Fatal(err)+ }+ cell := treenode.GetNodeInTree(restored, table.ID).LastChild.FirstChild+ if cell.TableCellRich == nil || cell.TableCellRich.Content != source {+ t.Fatalf("saved rich source changed: %#v", cell.TableCellRich)+ }+ }+}diff --git a/kernel/model/transaction.go b/kernel/model/transaction.goindex c2c7f346f8..a875dc5798 100644--- a/kernel/model/transaction.go+++ b/kernel/model/transaction.go@@ -1911,7 +1911,9 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {if ast.NodeTextMark == n.Type {if n.IsTextMarkType("inline-math") {- if "" == strings.TrimSpace(n.TextMarkInlineMathContent) {+ // 富文本单元格中的行级公式是派生投影,空公式块也需要保留对应节点。+ if "" == strings.TrimSpace(n.TextMarkInlineMathContent) &&+ (nil == n.Parent || nil == n.Parent.TableCellRich) {// 剔除空白的行级公式unlinks = append(unlinks, n)}diff --git a/kernel/treenode/table_cell_rich_test.go b/kernel/treenode/table_cell_rich_test.goindex 9d91f0d8b6..170040427e 100644--- a/kernel/treenode/table_cell_rich_test.go+++ b/kernel/treenode/table_cell_rich_test.go@@ -113,6 +113,7 @@ func TestTableCellRichFrontendProjectionParity(t *testing.T) {`var(--b3-font-family-editor), var(--b3-font-family);"}`for _, source := range []string{"- **first**\n- second\n\n```go\na < b && c\nd\n```\n\n$$\nx < y\n$$",+ "- list\n\n$$\n\n$$","```go\na < b && c\n```\n" + `{: id="20260921000000-code001" linewrap="false" linenumber="true" ligatures="false"}`," ((20240101000000-abcdefg 'reference')) `a & b`",styled,