From efd668f956fe712ee9311942ff0d8bc9dd86244d Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 27 May 2022 18:05:27 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=A4=A7=E7=BA=B2=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=96=87=E6=A1=A3=E6=A0=87=E9=A2=98=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E7=BC=A9=E8=BF=9B=20https://github.com/siyuan-note/si?= =?UTF-8?q?yuan/issues/5011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/outline.go | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/kernel/model/outline.go b/kernel/model/outline.go index ed8238aa1..b2f35e549 100644 --- a/kernel/model/outline.go +++ b/kernel/model/outline.go @@ -82,30 +82,22 @@ func Outline(rootID string) (ret []*Path, err error) { } ret = toFlatTree(blocks, 0, "outline") - 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, - }) - } - } + resetDepth(ret) return } -func resetDepth(b *Block, depth int) { - b.Depth = depth - b.Count = len(b.Children) - for _, c := range b.Children { - resetDepth(c, depth+1) +func resetDepth(paths []*Path) { + for _, p := range paths { + for _, b := range p.Blocks { + resetDepth0(b, p.Depth) + } + } +} + +func resetDepth0(b *Block, depth int) { + b.Depth = depth + 1 + b.Count = len(b.Children) + for _, c := range b.Children { + resetDepth0(c, depth+1) } }