Sfoglia il codice sorgente

:bug: 删除文档后应关闭该文档的关系图、大纲和反链页签 https://github.com/siyuan-note/siyuan/issues/6468

Liang Ding 2 anni fa
parent
commit
0e651b097f
3 ha cambiato i file con 29 aggiunte e 7 eliminazioni
  1. 0 7
      kernel/api/filetree.go
  2. 10 0
      kernel/model/file.go
  3. 19 0
      kernel/util/path.go

+ 0 - 7
kernel/api/filetree.go

@@ -310,13 +310,6 @@ func removeDoc(c *gin.Context) {
 		ret.Msg = err.Error()
 		return
 	}
-
-	evt := util.NewCmdResult("remove", 0, util.PushModeBroadcast, util.PushModeNone)
-	evt.Data = map[string]interface{}{
-		"box":  notebook,
-		"path": p,
-	}
-	util.PushEvent(evt)
 }
 
 func removeDocs(c *gin.Context) {

+ 10 - 0
kernel/model/file.go

@@ -1227,6 +1227,8 @@ func removeDoc(box *Box, p string) (err error) {
 	copyDocAssetsToDataAssets(box.ID, p)
 
 	rootID := tree.ID
+	var removeIDs []string
+	removeIDs = append(removeIDs, rootID)
 	dir := path.Dir(p)
 	childrenDir := path.Join(dir, rootID)
 	existChildren := box.Exist(childrenDir)
@@ -1246,6 +1248,8 @@ func removeDoc(box *Box, p string) (err error) {
 
 	if existChildren {
 		box.Remove(childrenDir)
+		ids := util.GetChildDocIDs(filepath.Join(util.DataDir, tree.Box, childrenDir))
+		removeIDs = append(removeIDs, ids...)
 	}
 
 	treenode.RemoveBlockTreesByPathPrefix(childrenDir)
@@ -1259,6 +1263,12 @@ func removeDoc(box *Box, p string) (err error) {
 	}
 
 	cache.RemoveDocIAL(p)
+
+	evt := util.NewCmdResult("remove", 0, util.PushModeBroadcast, util.PushModeNone)
+	evt.Data = map[string]interface{}{
+		"ids": removeIDs,
+	}
+	util.PushEvent(evt)
 	return
 }
 

+ 19 - 0
kernel/util/path.go

@@ -202,3 +202,22 @@ func FilterSelfChildDocs(paths []string) (ret []string) {
 	}
 	return
 }
+
+func GetChildDocIDs(parentDocDirAbsPath string) (ret []string) {
+	if !gulu.File.IsDir(parentDocDirAbsPath) {
+		return
+	}
+
+	filepath.Walk(parentDocDirAbsPath, func(path string, info os.FileInfo, err error) error {
+		if info.IsDir() {
+			return nil
+		}
+		if !strings.HasSuffix(path, ".sy") {
+			return nil
+		}
+		id := path[len(parentDocDirAbsPath)+1 : len(path)-3]
+		ret = append(ret, id)
+		return nil
+	})
+	return
+}