This commit is contained in:
Liang Ding 2023-02-06 18:03:29 +08:00
parent 2f8d75075e
commit 4bdc3536a3
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
3 changed files with 58 additions and 0 deletions

View file

@ -115,6 +115,43 @@ func RecentUpdatedBlocks() (ret []*Block) {
return
}
func TransferBlockRef(fromID, toID string) (err error) {
toTree, _ := loadTreeByBlockID(toID)
if nil == toTree {
err = ErrBlockNotFound
return
}
toNode := treenode.GetNodeInTree(toTree, toID)
if nil == toNode {
err = ErrBlockNotFound
return
}
toRefText := getNodeRefText(toNode)
refIDs, _ := sql.QueryRefIDsByDefID(fromID, false)
for _, refID := range refIDs {
tree, _ := loadTreeByBlockID(refID)
if nil == tree {
continue
}
node := treenode.GetNodeInTree(tree, refID)
textMarks := node.ChildrenByType(ast.NodeTextMark)
for _, textMark := range textMarks {
if textMark.IsTextMarkType("block-ref") && textMark.TextMarkBlockRefID == fromID {
textMark.TextMarkBlockRefID = toID
if "s" == textMark.TextMarkBlockRefSubtype {
textMark.TextMarkTextContent = toRefText
}
}
}
if err = indexWriteJSONQueue(tree); nil != err {
return
}
}
return
}
func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
refTree, err := loadTreeByBlockID(refID)
if nil != err {