From a785cd15c0708ac1617879bddd7211fe22371043 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 3 Jan 2024 17:38:17 +0800 Subject: [PATCH] :bug: The parent block field of the blocks under the heading block is calculated incorrectly https://github.com/siyuan-note/siyuan/issues/9869 --- kernel/model/transaction.go | 43 ++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index e149f3345..96560f969 100644 --- a/kernel/model/transaction.go +++ b/kernel/model/transaction.go @@ -314,6 +314,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { headingChildren = treenode.GetHeadingFold(headingChildren) } + refreshHeadingChildrenUpdated(srcNode, time.Now().Format("20060102150405")) + var srcEmptyList *ast.Node if ast.NodeListItem == srcNode.Type && srcNode.Parent.FirstChild == srcNode && srcNode.Parent.LastChild == srcNode { // 列表中唯一的列表项被移除后,该列表就为空了 @@ -366,6 +368,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { srcEmptyList.Unlink() } + refreshHeadingChildrenUpdated(srcNode, time.Now().Format("20060102150405")) + refreshUpdated(srcNode) refreshUpdated(srcTree.Root) if err = tx.writeTree(srcTree); nil != err { @@ -444,6 +448,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) { } } + refreshHeadingChildrenUpdated(srcNode, time.Now().Format("20060102150405")) + refreshUpdated(srcNode) refreshUpdated(srcTree.Root) if err = tx.writeTree(srcTree); nil != err { @@ -752,6 +758,9 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) { // 列表块撤销状态异常 https://github.com/siyuan-note/siyuan/issues/3985 node.Next.Unlink() } + + refreshHeadingChildrenUpdated(node, time.Now().Format("20060102150405")) + node.Unlink() if nil != parent && ast.NodeListItem == parent.Type && nil == parent.FirstChild { // 保持空列表项 @@ -961,6 +970,8 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) { } } + refreshHeadingChildrenUpdated(insertedNode, time.Now().Format("20060102150405")) + createdUpdated(insertedNode) tx.nodes[insertedNode.ID] = insertedNode if err = tx.writeTree(tree); nil != err { @@ -1048,14 +1059,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { treenode.MoveFoldHeading(updatedNode, oldNode) } - if ast.NodeHeading == oldNode.Type && ast.NodeHeading != updatedNode.Type { - // 将标题块更新为非标题块时需要更新下方块的 parent id - children := treenode.HeadingChildren(oldNode) - updated := time.Now().Format("20060102150405") - for _, child := range children { - child.SetIALAttr("updated", updated) - } - } + refreshHeadingChildrenUpdated(oldNode, time.Now().Format("20060102150405")) cache.PutBlockIAL(updatedNode.ID, parse.IAL2Map(updatedNode.KramdownIAL)) @@ -1064,15 +1068,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { oldNode.Unlink() createdUpdated(updatedNode) - if ast.NodeHeading != oldNode.Type && ast.NodeHeading == updatedNode.Type { - // 将非标题块更新为标题块时需要更新下方块的 parent id - // The parent block field of the blocks under the heading block is calculated incorrectly https://github.com/siyuan-note/siyuan/issues/9869 - children := treenode.HeadingChildren(updatedNode) - updated := updatedNode.IALAttr("updated") - for _, child := range children { - child.SetIALAttr("updated", updated) - } - } + refreshHeadingChildrenUpdated(updatedNode, updatedNode.IALAttr("updated")) tx.nodes[updatedNode.ID] = updatedNode if err = tx.writeTree(tree); nil != err { @@ -1085,6 +1081,19 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) { return } +func refreshHeadingChildrenUpdated(heading *ast.Node, updated string) { + if nil == heading || ast.NodeHeading != heading.Type { + return + } + + // 将非标题块更新为标题块时需要更新下方块的 parent id + // The parent block field of the blocks under the heading block is calculated incorrectly https://github.com/siyuan-note/siyuan/issues/9869 + children := treenode.HeadingChildren(heading) + for _, child := range children { + child.SetIALAttr("updated", updated) + } +} + func upsertAvBlockRel(node *ast.Node) { ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus { if !entering {