From dcbcf7f3a7e3ca16196c727a5d7387db4c1972e0 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 13 Jun 2022 19:59:14 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E6=9F=A5=E6=89=BE=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E5=90=8D=E4=BB=A5=E5=90=8E=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E9=94=9A=E6=96=87=E6=9C=AC=E6=9C=AA=E8=B7=9F?= =?UTF-8?q?=E9=9A=8F=E6=94=B9=E5=8F=98=20Fix=20https://github.com/siyuan-n?= =?UTF-8?q?ote/siyuan/issues/5175?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/search.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/model/search.go b/kernel/model/search.go index 459c6974f..cd777301e 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -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() {