🎨 Blocks below other non-folded headings are no longer moved when moving a folded heading Fix https://github.com/siyuan-note/siyuan/issues/8321

This commit is contained in:
Daniel 2023-05-22 11:06:28 +08:00
parent cc9dce106a
commit feb4d7e0cd
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 14 additions and 0 deletions

View file

@ -257,7 +257,10 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
var headingChildren []*ast.Node
if isMovingFoldHeading := ast.NodeHeading == srcNode.Type && "1" == srcNode.IALAttr("fold"); isMovingFoldHeading {
headingChildren = treenode.HeadingChildren(srcNode)
// Blocks below other non-folded headings are no longer moved when moving a folded heading https://github.com/siyuan-note/siyuan/issues/8321
headingChildren = treenode.GetHeadingFold(headingChildren)
}
var srcEmptyList *ast.Node
if ast.NodeListItem == srcNode.Type && srcNode.Parent.FirstChild == srcNode && srcNode.Parent.LastChild == srcNode {
// 列表中唯一的列表项被移除后,该列表就为空了
@ -290,6 +293,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
if ast.NodeHeading == targetNode.Type && "1" == targetNode.IALAttr("fold") {
targetChildren := treenode.HeadingChildren(targetNode)
targetChildren = treenode.GetHeadingFold(targetChildren)
if l := len(targetChildren); 0 < l {
targetNode = targetChildren[l-1]
}

View file

@ -72,6 +72,15 @@ func IsInFoldedHeading(node, currentHeading *ast.Node) bool {
return IsInFoldedHeading(heading, currentHeading)
}
func GetHeadingFold(nodes []*ast.Node) (ret []*ast.Node) {
for _, n := range nodes {
if "1" == n.IALAttr("heading-fold") {
ret = append(ret, n)
}
}
return
}
func HeadingChildren(heading *ast.Node) (ret []*ast.Node) {
start := heading.Next
if nil == start {