🎨 块引用与所引用的内容块进行交换 https://github.com/siyuan-note/siyuan/issues/4981
This commit is contained in:
parent
a0988df153
commit
b774f98044
1 changed files with 12 additions and 8 deletions
|
@ -110,10 +110,11 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
if nil == defNode {
|
||||
return
|
||||
}
|
||||
var defNodeChildren []*ast.Node
|
||||
if ast.NodeListItem == defNode.Parent.Type {
|
||||
defNode = defNode.Parent
|
||||
} else if ast.NodeHeading == defNode.Type && includeChildren {
|
||||
|
||||
defNodeChildren = treenode.HeadingChildren(defNode)
|
||||
}
|
||||
|
||||
refPivot := parse.NewParagraph()
|
||||
|
@ -141,21 +142,24 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
} else {
|
||||
if ast.NodeListItem == refNode.Type {
|
||||
newID := ast.NewNodeID()
|
||||
li := &ast.Node{ID: newID, Type: ast.NodeListItem, ListData: &ast.ListData{Typ: refNode.Parent.ListData.Typ}}
|
||||
li.SetIALAttr("id", newID)
|
||||
li.SetIALAttr("updated", newID[:14])
|
||||
li.AppendChild(defNode)
|
||||
refPivot.InsertAfter(li)
|
||||
|
||||
newID = ast.NewNodeID()
|
||||
list := &ast.Node{ID: newID, Type: ast.NodeList, ListData: &ast.ListData{Typ: refNode.Parent.ListData.Typ}}
|
||||
list.SetIALAttr("id", newID)
|
||||
list.SetIALAttr("updated", newID[:14])
|
||||
list.AppendChild(refNode)
|
||||
defNode.InsertAfter(list)
|
||||
|
||||
newID = ast.NewNodeID()
|
||||
li := &ast.Node{ID: newID, Type: ast.NodeListItem, ListData: &ast.ListData{Typ: refNode.Parent.ListData.Typ}}
|
||||
li.SetIALAttr("id", newID)
|
||||
li.SetIALAttr("updated", newID[:14])
|
||||
li.AppendChild(defNode)
|
||||
refPivot.InsertAfter(li)
|
||||
} else {
|
||||
defNode.InsertAfter(refNode)
|
||||
refPivot.InsertAfter(defNode)
|
||||
for i := len(defNodeChildren) - 1; -1 < i; i-- {
|
||||
refPivot.InsertAfter(defNodeChildren[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
refPivot.Unlink()
|
||||
|
|
Loading…
Add table
Reference in a new issue