mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-05 16:28:49 +01:00
This commit is contained in:
parent
2f8d75075e
commit
4bdc3536a3
3 changed files with 58 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue