mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 09:00:12 +01:00
🎨 改进块树数据索引稳定性 https://github.com/siyuan-note/siyuan/issues/7240
This commit is contained in:
parent
7ced94a194
commit
fafeecd3a9
2 changed files with 51 additions and 10 deletions
|
|
@ -285,6 +285,24 @@ func ParentNodes(node *ast.Node) (parents []*ast.Node) {
|
|||
return
|
||||
}
|
||||
|
||||
func ChildBlockNodes(node *ast.Node) (children []*ast.Node) {
|
||||
children = []*ast.Node{}
|
||||
if !node.IsContainerBlock() || ast.NodeDocument == node.Type {
|
||||
children = append(children, node)
|
||||
return
|
||||
}
|
||||
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
children = append(children, n)
|
||||
return ast.WalkContinue
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func ParentBlock(node *ast.Node) *ast.Node {
|
||||
for p := node.Parent; nil != p; p = p.Parent {
|
||||
if "" != p.ID && p.IsBlock() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue