From 8a30d84dfbf69f7735ad7657523ab9e0d42354b5 Mon Sep 17 00:00:00 2001 From: Mikhail Chekan Date: Fri, 1 Oct 2021 17:18:11 +0800 Subject: [PATCH] Fix missing subhyphae in the tree view --- tree/tree.go | 22 ++++++++++++++++++---- tree/view.qtpl | 2 +- tree/view.qtpl.go | 10 +++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tree/tree.go b/tree/tree.go index c86d390..f5b2ce5 100644 --- a/tree/tree.go +++ b/tree/tree.go @@ -104,7 +104,7 @@ func Tree(hyphaName string) (siblingsHTML, childrenHTML, prev, next string) { wg.Done() }() go func() { - children = figureOutChildren(hyphaName, descendantsPool).children + children = figureOutChildren(hyphaName, descendantsPool, true).children wg.Done() }() wg.Wait() @@ -128,10 +128,11 @@ func Tree(hyphaName string) (siblingsHTML, childrenHTML, prev, next string) { type child struct { name string + exists bool children []child } -func figureOutChildren(hyphaName string, subhyphaePool map[string]bool) child { +func figureOutChildren(hyphaName string, subhyphaePool map[string]bool, exists bool) child { var ( nestLevel = strings.Count(hyphaName, "/") adopted = make([]child, 0) @@ -140,10 +141,23 @@ func figureOutChildren(hyphaName string, subhyphaePool map[string]bool) child { subnestLevel := strings.Count(subhyphaName, "/") if subnestLevel-1 == nestLevel && path.Dir(subhyphaName) == hyphaName { delete(subhyphaePool, subhyphaName) - adopted = append(adopted, figureOutChildren(subhyphaName, subhyphaePool)) + adopted = append(adopted, figureOutChildren(subhyphaName, subhyphaePool, true)) } } - return child{hyphaName, adopted} + for descName, _ := range subhyphaePool { + if strings.HasPrefix(descName, hyphaName) { + var ( + rawSubPath = strings.TrimPrefix(descName, hyphaName)[1:] + slashIdx = strings.IndexRune(rawSubPath, '/') + ) + if slashIdx > -1 { + var sibPath = descName[:slashIdx+len(hyphaName)+1] + adopted = append(adopted, figureOutChildren(sibPath, subhyphaePool, false)) + } // `else` never happens? + } + } + + return child{hyphaName, exists, adopted} } type sibling struct { diff --git a/tree/view.qtpl b/tree/view.qtpl index 562e511..6d047f0 100644 --- a/tree/view.qtpl +++ b/tree/view.qtpl @@ -20,7 +20,7 @@ pseudographics: }) %}
  • - + {%s util.BeautifulName(path.Base(c.name)) %} {% if len(c.children) > 0 %} diff --git a/tree/view.qtpl.go b/tree/view.qtpl.go index 2f1b136..f005c67 100644 --- a/tree/view.qtpl.go +++ b/tree/view.qtpl.go @@ -82,7 +82,15 @@ func streamchildHTML(qw422016 *qt422016.Writer, c *child) { //line tree/view.qtpl:21 qw422016.N().S(`
  • -