mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-18 01:50:58 +08:00
🐛 查找替换文档名以后动态引用锚文本未跟随改变 Fix https://github.com/siyuan-note/siyuan/issues/5175
This commit is contained in:
parent
3db97a8f59
commit
dcbcf7f3a7
@ -133,6 +133,8 @@ func FindReplace(keyword, replacement string, ids []string) (err error) {
|
||||
}
|
||||
|
||||
ids = util.RemoveDuplicatedElem(ids)
|
||||
var renameRoots []*ast.Node
|
||||
renameRootTitles := map[string]string{}
|
||||
for _, id := range ids {
|
||||
var tree *parse.Tree
|
||||
tree, err = loadTreeByBlockID(id)
|
||||
@ -154,7 +156,8 @@ func FindReplace(keyword, replacement string, ids []string) (err error) {
|
||||
case ast.NodeDocument:
|
||||
title := n.IALAttr("title")
|
||||
if strings.Contains(title, keyword) {
|
||||
n.SetIALAttr("title", strings.ReplaceAll(title, keyword, replacement))
|
||||
renameRootTitles[n.ID] = strings.ReplaceAll(title, keyword, replacement)
|
||||
renameRoots = append(renameRoots, n)
|
||||
}
|
||||
case ast.NodeText, ast.NodeLinkText, ast.NodeLinkTitle, ast.NodeCodeSpanContent, ast.NodeCodeBlockCode, ast.NodeInlineMathContent, ast.NodeMathBlockContent:
|
||||
if bytes.Contains(n.Tokens, []byte(keyword)) {
|
||||
@ -169,6 +172,11 @@ func FindReplace(keyword, replacement string, ids []string) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
for _, renameRoot := range renameRoots {
|
||||
newTitle := renameRootTitles[renameRoot.ID]
|
||||
RenameDoc(renameRoot.Box, renameRoot.Path, newTitle)
|
||||
}
|
||||
|
||||
WaitForWritingFiles()
|
||||
if 1 < len(ids) {
|
||||
go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user