From 49e5ca8a6fcdb22cc7f8c9536cc1ab973a351b11 Mon Sep 17 00:00:00 2001 From: Mikhail Chekan Date: Fri, 1 Oct 2021 16:57:00 +0800 Subject: [PATCH 1/2] Show ghost siblings --- tree/tree.go | 32 +++++++++++++++++++++++++++++--- tree/view.qtpl | 2 +- tree/view.qtpl.go | 10 +++++++++- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/tree/tree.go b/tree/tree.go index b04e1c4..c86d390 100644 --- a/tree/tree.go +++ b/tree/tree.go @@ -12,11 +12,27 @@ import ( ) func findSiblingsAndDescendants(hyphaName string) ([]*sibling, map[string]bool) { + hyphaDir := "" + if hyphaRawDir := path.Dir(hyphaName); hyphaRawDir != "." { + hyphaDir = hyphaRawDir + } var ( - siblings = []*sibling{&sibling{hyphaName, 0, 0}} + siblingsMap = make(map[string]bool) siblingCheck = func(h *hyphae.Hypha) hyphae.CheckResult { - if path.Dir(hyphaName) == path.Dir(h.Name) && h.Name != hyphaName { - siblings = append(siblings, &sibling{h.Name, 0, 0}) + // I don't like this double comparison, but it is only the way to circumvent some flickups + if strings.HasPrefix(h.Name, hyphaDir) && h.Name != hyphaDir && h.Name != hyphaName { + var ( + rawSubPath = strings.TrimPrefix(h.Name, hyphaDir)[1:] + slashIdx = strings.IndexRune(rawSubPath, '/') + ) + if slashIdx > -1 { + var sibPath = h.Name[:slashIdx+len(hyphaDir)+1] + if _, exists := siblingsMap[sibPath]; !exists { + siblingsMap[sibPath] = false + } + } else { // it is a straight sibling + siblingsMap[h.Name] = true + } } return hyphae.CheckContinue } @@ -31,9 +47,18 @@ func findSiblingsAndDescendants(hyphaName string) ([]*sibling, map[string]bool) i7n = hyphae.NewIteration() ) + siblingsMap[hyphaName] = true + i7n.AddCheck(siblingCheck) i7n.AddCheck(descendantCheck) i7n.Ignite() + + siblings := make([]*sibling, len(siblingsMap)) + sibIdx := 0 + for sibName, exists := range siblingsMap { + siblings[sibIdx] = &sibling{sibName, 0, 0, exists} + sibIdx++ + } sort.Slice(siblings, func(i, j int) bool { return siblings[i].name < siblings[j].name }) @@ -125,6 +150,7 @@ type sibling struct { name string directSubhyphaeCount int indirectSubhyphaeCount int + exists bool } func subhyphaeMatrix(children []child) (html string) { diff --git a/tree/view.qtpl b/tree/view.qtpl index bcaa28e..562e511 100644 --- a/tree/view.qtpl +++ b/tree/view.qtpl @@ -36,7 +36,7 @@ pseudographics: {% func siblingHTML(s *sibling) %}
  • - + {%s util.BeautifulName(path.Base(s.name)) %} {% if s.directSubhyphaeCount > 0 %} diff --git a/tree/view.qtpl.go b/tree/view.qtpl.go index e429bb6..2f1b136 100644 --- a/tree/view.qtpl.go +++ b/tree/view.qtpl.go @@ -156,7 +156,15 @@ func streamsiblingHTML(qw422016 *qt422016.Writer, s *sibling) { //line tree/view.qtpl:37 qw422016.N().S(`
  • - -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(`
  • -