syncToSrc updates the view tree to match the sync tree, using ConfigChildren to maximally preserve existing tree elements. init means we are doing initial build, and depth tracks depth (only during init).
(tvIndex *int, init bool, depth int)
| 60 | // init means we are doing initial build, and depth tracks depth |
| 61 | // (only during init). |
| 62 | func (tr *Tree) syncToSrc(tvIndex *int, init bool, depth int) { |
| 63 | sn := tr.SyncNode |
| 64 | // root must keep the same name for continuity with surrounding context |
| 65 | if tr != tr.root { |
| 66 | nm := "tv_" + sn.AsTree().Name |
| 67 | tr.SetName(nm) |
| 68 | } |
| 69 | tr.viewIndex = *tvIndex |
| 70 | *tvIndex++ |
| 71 | if init && depth >= tr.root.OpenDepth { |
| 72 | tr.SetClosed(true) |
| 73 | } |
| 74 | skids := sn.AsTree().Children |
| 75 | p := make(tree.TypePlan, 0, len(skids)) |
| 76 | typ := tr.NodeType() |
| 77 | for _, skid := range skids { |
| 78 | p.Add(typ, "tv_"+skid.AsTree().Name) |
| 79 | } |
| 80 | tree.Update(tr, p) |
| 81 | idx := 0 |
| 82 | for _, skid := range sn.AsTree().Children { |
| 83 | if len(tr.Children) <= idx { |
| 84 | break |
| 85 | } |
| 86 | vk := AsTree(tr.Children[idx]) |
| 87 | vk.setSyncNode(skid, tvIndex, init, depth+1) |
| 88 | idx++ |
| 89 | } |
| 90 | if !sn.AsTree().HasChildren() { |
| 91 | tr.SetClosed(true) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // Label returns the display label for this node, |
| 96 | // satisfying the [labels.Labeler] interface. |
no test coverage detected