🐛 查找替换文档名以后动态引用锚文本未跟随改变 Fix https://github.com/siyuan-note/siyuan/issues/5175

This commit is contained in:
Liang Ding 2022-06-13 19:59:14 +08:00
parent 3db97a8f59
commit dcbcf7f3a7
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D

View File

@ -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() {