From 75925c9e4f72d357e8d31f5800e207d04e774445 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 4 Nov 2022 15:35:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:octocat:=20=E8=A1=A5=E5=85=85=20PR=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=20https://github.com/siyuan-note/siyuan/pull?= =?UTF-8?q?/6471?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/file.go | 32 +++++++++++++++++++++++--------- kernel/util/path.go | 3 ++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index ce2acf031..ee90f0a02 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1028,12 +1028,6 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e } func MoveDocs(fromPaths []string, toPath string) (err error) { - util.PushEndlessProgress(Conf.Language(116)) - - WaitForWritingFiles() - fromPaths = util.FilterMoveDocFromPaths(fromPaths, toPath) - pathsBoxes := getBoxesByPaths(fromPaths) - toID := strings.TrimSuffix(path.Base(toPath), ".sy") toBlock := treenode.GetBlockTree(toID) if nil == toBlock { @@ -1047,6 +1041,14 @@ func MoveDocs(fromPaths []string, toPath string) (err error) { return } + fromPaths = util.FilterMoveDocFromPaths(fromPaths, toPath) + pathsBoxes := getBoxesByPaths(fromPaths) + needShowProgress := 32 < len(fromPaths) + if needShowProgress { + util.PushEndlessProgress(Conf.Language(116)) + } + + WaitForWritingFiles() for fromPath, fromBox := range pathsBoxes { _, err = moveDoc(fromBox, fromPath, toBox, toPath) if nil != err { @@ -1056,9 +1058,11 @@ func MoveDocs(fromPaths []string, toPath string) (err error) { cache.ClearDocsIAL() IncSync() - util.PushEndlessProgress(Conf.Language(113)) - sql.WaitForWritingDatabase() - util.ReloadUI() + if needShowProgress { + util.PushEndlessProgress(Conf.Language(113)) + sql.WaitForWritingDatabase() + util.ReloadUI() + } return } @@ -1167,6 +1171,16 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string) (newPath moveTree(tree) moveSorts(tree.ID, fromBox.ID, toBox.ID) } + + evt := util.NewCmdResult("moveDoc", 0, util.PushModeBroadcast, util.PushModeNone) + evt.Data = map[string]interface{}{ + "fromNotebook": fromBox.ID, + "fromPath": fromPath, + "toNotebook": toBox.ID, + "toPath": toPath, + "newPath": newPath, + } + util.PushEvent(evt) return } diff --git a/kernel/util/path.go b/kernel/util/path.go index 54dad6677..2c82e3cea 100644 --- a/kernel/util/path.go +++ b/kernel/util/path.go @@ -178,11 +178,12 @@ func NormalizeEndpoint(endpoint string) string { func FilterMoveDocFromPaths(fromPaths []string, toPath string) (retFromPaths []string) { fromPaths = append(fromPaths, toPath) retFromPaths = FilterSelfChildDocs(fromPaths) + retFromPaths = gulu.Str.ExcludeElem(retFromPaths, []string{toPath}) return } func FilterSelfChildDocs(paths []string) (ret []string) { - sort.Slice(paths, func(i, j int) bool { return len(paths[i]) < len(paths[j]) }) + sort.Slice(paths, func(i, j int) bool { return strings.Count(paths[i], "/") < strings.Count(paths[j], "/") }) dirs := map[string]string{} for _, fromPath := range paths { From f0088ccf86703a14a39bbf87fe13f8bb542f8efd Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 4 Nov 2022 15:44:39 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:bug:=20=E6=97=A0=E6=B3=95=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E5=8C=85=E5=90=AB=20HTML=20=E8=BD=AC=E4=B9=89?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E5=86=85=E5=AE=B9=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/6476?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/search.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/model/search.go b/kernel/model/search.go index 5994fa606..6b2ec11af 100644 --- a/kernel/model/search.go +++ b/kernel/model/search.go @@ -207,6 +207,17 @@ func FindReplace(keyword, replacement string, ids []string) (err error) { n.Tokens = bytes.ReplaceAll(n.Tokens, []byte(keyword), []byte(replacement)) } case ast.NodeTextMark: + if n.IsTextMarkType("code") { + escapedKey := html.EscapeString(keyword) + if strings.Contains(n.TextMarkTextContent, escapedKey) { + n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, escapedKey, replacement) + } + } else { + if bytes.Contains(n.Tokens, []byte(keyword)) { + n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement) + } + } + if strings.Contains(n.TextMarkTextContent, keyword) { n.TextMarkTextContent = strings.ReplaceAll(n.TextMarkTextContent, keyword, replacement) }