🎨 块引用与所引用的内容块进行交换 https://github.com/siyuan-note/siyuan/issues/4981

This commit is contained in:
Liang Ding 2022-10-02 22:44:20 +08:00
parent 14995a815d
commit a0988df153
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
2 changed files with 7 additions and 4 deletions

View File

@ -42,7 +42,8 @@ func swapBlockRef(c *gin.Context) {
refID := arg["refID"].(string)
defID := arg["defID"].(string)
err := model.SwapBlockRef(refID, defID)
includeChildren := arg["includeChildren"].(bool)
err := model.SwapBlockRef(refID, defID, includeChildren)
if nil != err {
ret.Code = -1
ret.Msg = err.Error()

View File

@ -90,7 +90,7 @@ func RecentUpdatedBlocks() (ret []*Block) {
return
}
func SwapBlockRef(refID, defID string) (err error) {
func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
refTree, err := loadTreeByBlockID(refID)
if nil != err {
return
@ -112,6 +112,8 @@ func SwapBlockRef(refID, defID string) (err error) {
}
if ast.NodeListItem == defNode.Parent.Type {
defNode = defNode.Parent
} else if ast.NodeHeading == defNode.Type && includeChildren {
}
refPivot := parse.NewParagraph()
@ -142,14 +144,14 @@ func SwapBlockRef(refID, defID string) (err error) {
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(refNode)
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(defNode)
list.AppendChild(refNode)
defNode.InsertAfter(list)
} else {
defNode.InsertAfter(refNode)