mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 05:11:03 +08:00
🎨 块引用与所引用的内容块进行交换 https://github.com/siyuan-note/siyuan/issues/4981
This commit is contained in:
parent
14995a815d
commit
a0988df153
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user