🎨 Improve reference count update after moving container blocks https://github.com/siyuan-note/siyuan/issues/15289

This commit is contained in:
Daniel 2025-07-17 12:00:07 +08:00
parent d58829a855
commit d3357af944
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 25 additions and 9 deletions

View file

@ -1612,10 +1612,10 @@ func (tx *Transaction) writeTree(tree *parse.Tree) (err error) {
return
}
func getRefsCacheByDefNode(updateNode *ast.Node) (ret []*sql.Ref, changedParentNodes []*ast.Node) {
func getRefsCacheByDefNode(updateNode *ast.Node) (ret []*sql.Ref, changedParentNodes, changedChildNodes []*ast.Node) {
ret = sql.GetRefsCacheByDefID(updateNode.ID)
if nil != updateNode.Parent && ast.NodeDocument != updateNode.Parent.Type &&
updateNode.Parent.IsContainerBlock() && updateNode == treenode.FirstLeafBlock(updateNode.Parent) { // 容器块下第一个叶子块
updateNode.Parent.IsContainerBlock() && updateNode == treenode.FirstLeafBlock(updateNode.Parent) {
// 如果是容器块下第一个叶子块,则需要向上查找引用
for parent := updateNode.Parent; nil != parent; parent = parent.Parent {
if ast.NodeDocument == parent.Type {
@ -1629,6 +1629,21 @@ func getRefsCacheByDefNode(updateNode *ast.Node) (ret []*sql.Ref, changedParentN
}
}
}
if ast.NodeDocument != updateNode.Type && updateNode.IsContainerBlock() {
// 如果是容器块,则需要向下查找引用
ast.Walk(updateNode, func(n *ast.Node, entering bool) ast.WalkStatus {
if !entering || !n.IsBlock() {
return ast.WalkContinue
}
childRefs := sql.GetRefsCacheByDefID(n.ID)
if 0 < len(childRefs) {
ret = append(ret, childRefs...)
changedChildNodes = append(changedChildNodes, n)
}
return ast.WalkContinue
})
}
return
}