浏览代码

:art: 大纲面板加入文档标题并调整缩进 https://github.com/siyuan-note/siyuan/issues/5011

Liang Ding 3 年之前
父节点
当前提交
410251677c
共有 1 个文件被更改,包括 19 次插入11 次删除
  1. 19 11
      kernel/model/outline.go

+ 19 - 11
kernel/model/outline.go

@@ -82,22 +82,30 @@ func Outline(rootID string) (ret []*Path, err error) {
 	}
 
 	ret = toFlatTree(blocks, 0, "outline")
-	resetDepth(ret)
-	return
-}
-
-func resetDepth(paths []*Path) {
-	for _, p := range paths {
-		for _, b := range p.Blocks {
-			resetDepth0(b, p.Depth)
+	if 0 < len(ret) {
+		children := ret[0].Blocks
+		ret = nil
+		for _, b := range children {
+			resetDepth(b, 0)
+			ret = append(ret, &Path{
+				ID:      b.ID,
+				Box:     b.Box,
+				Name:    b.Content,
+				Type:    b.Type,
+				SubType: b.SubType,
+				Blocks:  b.Children,
+				Depth:   0,
+				Count:   b.Count,
+			})
 		}
 	}
+	return
 }
 
-func resetDepth0(b *Block, depth int) {
-	b.Depth = depth + 1
+func resetDepth(b *Block, depth int) {
+	b.Depth = depth
 	b.Count = len(b.Children)
 	for _, c := range b.Children {
-		resetDepth0(c, depth+1)
+		resetDepth(c, depth+1)
 	}
 }