From 0378cf52d51c29f2f535be12a14cc088e1048703 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Thu, 3 Nov 2022 18:48:11 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=96=87=E6=A1=A3=E6=A0=91=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20`Ctrl+Click`=20=E5=92=8C=20`Shift+=E2=86=91/?= =?UTF-8?q?=E2=86=93`=20=E8=BF=9B=E8=A1=8C=E5=A4=9A=E9=80=89=20https://git?= =?UTF-8?q?hub.com/siyuan-note/siyuan/issues/1359?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/file.go | 33 +++------------------------------ kernel/util/path.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/kernel/model/file.go b/kernel/model/file.go index e6b48d09f..8bacdb3a7 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1031,7 +1031,8 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e func MoveDocs(fromPaths []string, toPath string) (err error) { util.PushEndlessProgress(Conf.Language(116)) - fromPaths = filterFromPaths(fromPaths, toPath) + WaitForWritingFiles() + fromPaths = util.FilterFromPaths(fromPaths, toPath) pathsBoxes := getBoxesByPaths(fromPaths) toID := strings.TrimSuffix(path.Base(toPath), ".sy") @@ -1062,34 +1063,6 @@ func MoveDocs(fromPaths []string, toPath string) (err error) { return } -func filterFromPaths(fromPaths []string, toPath string) (retFromPaths []string) { - fromPaths = append(fromPaths, toPath) - retFromPaths = filterSelfChildDocs(fromPaths) - return -} - -func filterSelfChildDocs(paths []string) (ret []string) { - sort.Slice(paths, func(i, j int) bool { return len(paths[i]) < len(paths[j]) }) - - dirs := map[string]string{} - for _, fromPath := range paths { - dir := strings.TrimSuffix(fromPath, ".sy") - existParent := false - for d, _ := range dirs { - if strings.HasPrefix(fromPath, d) { - existParent = true - break - } - } - if existParent { - continue - } - dirs[dir] = fromPath - ret = append(ret, fromPath) - } - return -} - func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string) (newPath string, err error) { isSameBox := fromBox.ID == toBox.ID @@ -1217,7 +1190,7 @@ func RemoveDoc(boxID, p string) (err error) { func RemoveDocs(paths []string) (err error) { util.PushEndlessProgress(Conf.Language(116)) - paths = filterSelfChildDocs(paths) + paths = util.FilterSelfChildDocs(paths) pathsBoxes := getBoxesByPaths(paths) WaitForWritingFiles() for p, box := range pathsBoxes { diff --git a/kernel/util/path.go b/kernel/util/path.go index 5b290f151..c05f1f517 100644 --- a/kernel/util/path.go +++ b/kernel/util/path.go @@ -22,6 +22,7 @@ import ( "os" "path" "path/filepath" + "sort" "strings" "time" @@ -173,3 +174,31 @@ func NormalizeEndpoint(endpoint string) string { } return endpoint } + +func FilterFromPaths(fromPaths []string, toPath string) (retFromPaths []string) { + fromPaths = append(fromPaths, toPath) + retFromPaths = FilterSelfChildDocs(fromPaths) + return +} + +func FilterSelfChildDocs(paths []string) (ret []string) { + sort.Slice(paths, func(i, j int) bool { return len(paths[i]) < len(paths[j]) }) + + dirs := map[string]string{} + for _, fromPath := range paths { + dir := strings.TrimSuffix(fromPath, ".sy") + existParent := false + for d, _ := range dirs { + if strings.HasPrefix(fromPath, d) { + existParent = true + break + } + } + if existParent { + continue + } + dirs[dir] = fromPath + ret = append(ret, fromPath) + } + return +}