mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-15 08:30:42 +08:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
a7d3e8a0c8
@ -944,17 +944,45 @@ func DuplicateDoc(rootID string) (err error) {
|
|||||||
p := path.Join(path.Dir(tree.Path), tree.ID) + ".sy"
|
p := path.Join(path.Dir(tree.Path), tree.ID) + ".sy"
|
||||||
tree.Path = p
|
tree.Path = p
|
||||||
tree.HPath = tree.HPath + " " + titleSuffix
|
tree.HPath = tree.HPath + " " + titleSuffix
|
||||||
|
|
||||||
|
// 收集所有引用
|
||||||
|
refIDs := map[string]string{}
|
||||||
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if !entering || ast.NodeBlockRefID != n.Type {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
refIDs[n.TokensStr()] = "1"
|
||||||
|
return ast.WalkContinue
|
||||||
|
})
|
||||||
|
|
||||||
|
// 重置块 ID
|
||||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering || ast.NodeDocument == n.Type {
|
if !entering || ast.NodeDocument == n.Type {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
}
|
}
|
||||||
if n.IsBlock() && "" != n.ID {
|
if n.IsBlock() && "" != n.ID {
|
||||||
n.ID = ast.NewNodeID()
|
newID := ast.NewNodeID()
|
||||||
|
if "1" == refIDs[n.ID] {
|
||||||
|
// 如果是文档自身的内部引用
|
||||||
|
refIDs[n.ID] = newID
|
||||||
|
}
|
||||||
|
n.ID = newID
|
||||||
n.SetIALAttr("id", n.ID)
|
n.SetIALAttr("id", n.ID)
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 重置内部引用
|
||||||
|
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
if !entering || ast.NodeBlockRefID != n.Type {
|
||||||
|
return ast.WalkContinue
|
||||||
|
}
|
||||||
|
if "1" != refIDs[n.TokensStr()] {
|
||||||
|
n.Tokens = []byte(refIDs[n.TokensStr()])
|
||||||
|
}
|
||||||
|
return ast.WalkContinue
|
||||||
|
})
|
||||||
|
|
||||||
transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}}
|
transaction := &Transaction{DoOperations: []*Operation{{Action: "create", Data: tree}}}
|
||||||
err = PerformTransactions(&[]*Transaction{transaction})
|
err = PerformTransactions(&[]*Transaction{transaction})
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
Loading…
Reference in New Issue
Block a user