mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-01 06:18:49 +01:00
🎨 Improve priority of folding processing when headings and super blocks are mixed https://github.com/siyuan-note/siyuan/issues/9488
This commit is contained in:
parent
256e64e8b5
commit
5e6d94783b
5 changed files with 19 additions and 112 deletions
|
|
@ -62,20 +62,6 @@ func IsInFoldedHeading(node, currentHeading *ast.Node) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if ast.NodeSuperBlock == node.Type {
|
||||
// The super block below the folded heading contains headings of the same level and cannot be loaded https://github.com/siyuan-note/siyuan/issues/9162
|
||||
if nil == currentHeading {
|
||||
return false
|
||||
}
|
||||
|
||||
sbChildHeading := SuperBlockHeading(node)
|
||||
if nil != sbChildHeading {
|
||||
if sbChildHeading.HeadingLevel <= currentHeading.HeadingLevel {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
heading := HeadingParent(node)
|
||||
if nil == heading {
|
||||
return false
|
||||
|
|
@ -99,39 +85,6 @@ func GetHeadingFold(nodes []*ast.Node) (ret []*ast.Node) {
|
|||
return
|
||||
}
|
||||
|
||||
// HeadingChildren4Folding 获取标题下方所属该标题层级的所有节点,如果遇到超级块的话则递归获取超级块下方的所有节点。
|
||||
// 折叠和取消折叠要用这个函数单独处理 https://github.com/siyuan-note/siyuan/issues/9435
|
||||
func HeadingChildren4Folding(heading *ast.Node) (ret []*ast.Node) {
|
||||
start := heading.Next
|
||||
if nil == start {
|
||||
return
|
||||
}
|
||||
if ast.NodeKramdownBlockIAL == start.Type {
|
||||
start = start.Next // 跳过 heading 的 IAL
|
||||
}
|
||||
|
||||
currentLevel := heading.HeadingLevel
|
||||
for n := start; nil != n; n = n.Next {
|
||||
if ast.NodeHeading == n.Type {
|
||||
if currentLevel >= n.HeadingLevel {
|
||||
break
|
||||
}
|
||||
} else if ast.NodeSuperBlock == n.Type {
|
||||
ast.Walk(n, func(child *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !child.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
ret = append(ret, child)
|
||||
return ast.WalkContinue
|
||||
})
|
||||
continue
|
||||
}
|
||||
ret = append(ret, n)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func HeadingChildren(heading *ast.Node) (ret []*ast.Node) {
|
||||
start := heading.Next
|
||||
if nil == start {
|
||||
|
|
@ -147,36 +100,12 @@ func HeadingChildren(heading *ast.Node) (ret []*ast.Node) {
|
|||
if currentLevel >= n.HeadingLevel {
|
||||
break
|
||||
}
|
||||
} else if ast.NodeSuperBlock == n.Type {
|
||||
if h := SuperBlockHeading(n); nil != h {
|
||||
if currentLevel >= h.HeadingLevel {
|
||||
break
|
||||
}
|
||||
}
|
||||
} else if ast.NodeSuperBlockCloseMarker == n.Type {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, n)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func SuperBlockHeading(sb *ast.Node) *ast.Node {
|
||||
c := sb.FirstChild.Next.Next
|
||||
if nil == c {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ast.NodeHeading == c.Type {
|
||||
return c
|
||||
}
|
||||
|
||||
if ast.NodeSuperBlock == c.Type {
|
||||
return SuperBlockHeading(c)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func SuperBlockLastHeading(sb *ast.Node) *ast.Node {
|
||||
headings := sb.ChildrenByType(ast.NodeHeading)
|
||||
if 0 < len(headings) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue