Pārlūkot izejas kodu

:bug: Failed to rename the document after moving it https://github.com/siyuan-note/siyuan/issues/11661

Daniel 1 gadu atpakaļ
vecāks
revīzija
1b7be9b6f0
2 mainītis faili ar 25 papildinājumiem un 5 dzēšanām
  1. 1 4
      kernel/model/box.go
  2. 24 1
      kernel/model/file.go

+ 1 - 4
kernel/model/box.go

@@ -404,12 +404,9 @@ func moveTree(tree *parse.Tree) {
 
 
 func (box *Box) renameSubTrees(tree *parse.Tree) {
 func (box *Box) renameSubTrees(tree *parse.Tree) {
 	subFiles := box.ListFiles(tree.Path)
 	subFiles := box.ListFiles(tree.Path)
-	box.moveTrees0(subFiles)
-}
 
 
-func (box *Box) moveTrees0(files []*FileInfo) {
 	luteEngine := util.NewLute()
 	luteEngine := util.NewLute()
-	for _, subFile := range files {
+	for _, subFile := range subFiles {
 		if !strings.HasSuffix(subFile.path, ".sy") {
 		if !strings.HasSuffix(subFile.path, ".sy") {
 			continue
 			continue
 		}
 		}

+ 24 - 1
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)
 		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)
 		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 := util.NewCmdResult("moveDoc", 0, util.PushModeBroadcast)
 	evt.Data = map[string]interface{}{
 	evt.Data = map[string]interface{}{
 		"fromNotebook": fromBox.ID,
 		"fromNotebook": fromBox.ID,