🎨 块引用与所引用的内容块进行交换 https://github.com/siyuan-note/siyuan/issues/4981
This commit is contained in:
parent
f4a918cd5b
commit
da8b9a7d9c
1 changed files with 9 additions and 2 deletions
|
@ -113,13 +113,15 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
var defNodeChildren []*ast.Node
|
||||
if ast.NodeListItem == defNode.Parent.Type {
|
||||
defNode = defNode.Parent
|
||||
} else if ast.NodeHeading == defNode.Type && includeChildren {
|
||||
defNodeChildren = treenode.HeadingChildren(defNode)
|
||||
}
|
||||
if ast.NodeListItem == defNode.Type {
|
||||
for c := defNode.FirstChild; nil != c; c = c.Next {
|
||||
if ast.NodeList == c.Type {
|
||||
defNodeChildren = append(defNodeChildren, c)
|
||||
}
|
||||
}
|
||||
} else if ast.NodeHeading == defNode.Type && includeChildren {
|
||||
defNodeChildren = treenode.HeadingChildren(defNode)
|
||||
}
|
||||
|
||||
refPivot := parse.NewParagraph()
|
||||
|
@ -128,6 +130,11 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
if ast.NodeListItem == defNode.Type {
|
||||
if ast.NodeListItem == refNode.Type {
|
||||
defNode.InsertAfter(refNode)
|
||||
if !includeChildren {
|
||||
for _, c := range defNodeChildren {
|
||||
refNode.AppendChild(c)
|
||||
}
|
||||
}
|
||||
refPivot.InsertAfter(defNode)
|
||||
} else {
|
||||
newID := ast.NewNodeID()
|
||||
|
|
Loading…
Add table
Reference in a new issue