diff --git a/kernel/model/box.go b/kernel/model/box.go index 3e5e100f4..4fffcd864 100644 --- a/kernel/model/box.go +++ b/kernel/model/box.go @@ -404,12 +404,9 @@ func moveTree(tree *parse.Tree) { func (box *Box) renameSubTrees(tree *parse.Tree) { subFiles := box.ListFiles(tree.Path) - box.moveTrees0(subFiles) -} -func (box *Box) moveTrees0(files []*FileInfo) { luteEngine := util.NewLute() - for _, subFile := range files { + for _, subFile := range subFiles { if !strings.HasSuffix(subFile.path, ".sy") { continue } diff --git a/kernel/model/file.go b/kernel/model/file.go index 62d8ca02a..56ff36346 100644 --- a/kernel/model/file.go +++ b/kernel/model/file.go @@ -1477,7 +1477,8 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin } } - if fromBox.Exist(fromFolder) { + needMoveSubDocs := fromBox.Exist(fromFolder) + if needMoveSubDocs { // 移动子文档文件夹 newFolder := path.Join(toFolder, tree.ID) @@ -1532,6 +1533,28 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin moveSorts(tree.ID, fromBox.ID, toBox.ID) } + if needMoveSubDocs { + // 将其所有子文档的移动事件推送到前端 https://github.com/siyuan-note/siyuan/issues/11661 + subDocsFolder := path.Join(toFolder, tree.ID) + syFiles := listSyFiles(path.Join(toBox.ID, subDocsFolder)) + for _, syFile := range syFiles { + relPath := strings.TrimPrefix(syFile, "/"+path.Join(toBox.ID, toFolder)) + subFromPath := path.Join(path.Dir(fromPath), relPath) + subToPath := path.Join(toFolder, relPath) + + evt := util.NewCmdResult("moveDoc", 0, util.PushModeBroadcast) + evt.Data = map[string]interface{}{ + "fromNotebook": fromBox.ID, + "fromPath": subFromPath, + "toNotebook": toBox.ID, + "toPath": path.Dir(subToPath) + ".sy", + "newPath": subToPath, + } + evt.Callback = callback + util.PushEvent(evt) + } + } + evt := util.NewCmdResult("moveDoc", 0, util.PushModeBroadcast) evt.Data = map[string]interface{}{ "fromNotebook": fromBox.ID,