Browse Source

:bug: The blocks is not displayed after the folded heading is converted to a document Fix https://github.com/siyuan-note/siyuan/issues/9512

Daniel 1 year ago
parent
commit
43e2473217
1 changed files with 18 additions and 4 deletions
  1. 18 4
      kernel/model/heading.go

+ 18 - 4
kernel/model/heading.go

@@ -50,6 +50,10 @@ func (tx *Transaction) doFoldHeading(operation *Operation) (ret *TxErr) {
 	for _, child := range children {
 	for _, child := range children {
 		childrenIDs = append(childrenIDs, child.ID)
 		childrenIDs = append(childrenIDs, child.ID)
 		ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
 		ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
+			if !entering || !n.IsBlock() {
+				return ast.WalkContinue
+			}
+
 			n.SetIALAttr("fold", "1")
 			n.SetIALAttr("fold", "1")
 			n.SetIALAttr("heading-fold", "1")
 			n.SetIALAttr("heading-fold", "1")
 			return ast.WalkContinue
 			return ast.WalkContinue
@@ -86,6 +90,10 @@ func (tx *Transaction) doUnfoldHeading(operation *Operation) (ret *TxErr) {
 	children := treenode.HeadingChildren(heading)
 	children := treenode.HeadingChildren(heading)
 	for _, child := range children {
 	for _, child := range children {
 		ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
 		ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
+			if !entering {
+				return ast.WalkContinue
+			}
+
 			n.RemoveIALAttr("heading-fold")
 			n.RemoveIALAttr("heading-fold")
 			n.RemoveIALAttr("fold")
 			n.RemoveIALAttr("fold")
 			return ast.WalkContinue
 			return ast.WalkContinue
@@ -104,7 +112,6 @@ func (tx *Transaction) doUnfoldHeading(operation *Operation) (ret *TxErr) {
 	}
 	}
 	sql.UpsertTreeQueue(tree)
 	sql.UpsertTreeQueue(tree)
 
 
-	children = treenode.HeadingChildren(heading)
 	luteEngine := NewLute()
 	luteEngine := NewLute()
 	operation.RetData = renderBlockDOMByNodes(children, luteEngine)
 	operation.RetData = renderBlockDOMByNodes(children, luteEngine)
 	return
 	return
@@ -307,14 +314,21 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
 	// 折叠标题转换为文档时需要自动展开下方块 https://github.com/siyuan-note/siyuan/issues/2947
 	// 折叠标题转换为文档时需要自动展开下方块 https://github.com/siyuan-note/siyuan/issues/2947
 	children := treenode.HeadingChildren(headingNode)
 	children := treenode.HeadingChildren(headingNode)
 	for _, child := range children {
 	for _, child := range children {
-		child.RemoveIALAttr("heading-fold")
-		child.RemoveIALAttr("fold")
+		ast.Walk(child, func(n *ast.Node, entering bool) ast.WalkStatus {
+			if !entering {
+				return ast.WalkContinue
+			}
+
+			n.RemoveIALAttr("heading-fold")
+			n.RemoveIALAttr("fold")
+			return ast.WalkContinue
+		})
 	}
 	}
 	headingNode.RemoveIALAttr("fold")
 	headingNode.RemoveIALAttr("fold")
+	headingNode.RemoveIALAttr("heading-fold")
 
 
 	luteEngine := util.NewLute()
 	luteEngine := util.NewLute()
 	newTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument, ID: srcHeadingID}, Context: &parse.Context{ParseOption: luteEngine.ParseOptions}}
 	newTree := &parse.Tree{Root: &ast.Node{Type: ast.NodeDocument, ID: srcHeadingID}, Context: &parse.Context{ParseOption: luteEngine.ParseOptions}}
-	children = treenode.HeadingChildren(headingNode)
 	for _, c := range children {
 	for _, c := range children {
 		newTree.Root.AppendChild(c)
 		newTree.Root.AppendChild(c)
 	}
 	}