about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-02-11 20:58:05 +0100
committerbptato <nincsnevem662@gmail.com>2024-02-11 20:58:05 +0100
commita508582743cb392577853791e03d23066757bb1f (patch)
treee3bb75af99ad94b36cbb1249e05e3dded3233a46 /src
parent7f974324de185e5f8e6a8b5723ac70fa8beea47f (diff)
downloadchawan-a508582743cb392577853791e03d23066757bb1f.tar.gz
pager: fix discardTree
Diffstat (limited to 'src')
-rw-r--r--src/local/pager.nim10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 6a4f3522..cc33d06b 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -97,21 +97,23 @@ func getRoot(container: Container): Container =
   while c.parent != nil: c = c.parent
   return c
 
-iterator all_children(parent: Container): Container {.inline.} =
+# depth-first descendant iterator
+iterator descendants(parent: Container): Container {.inline.} =
   var stack = newSeqOfCap[Container](parent.children.len)
   for i in countdown(parent.children.high, 0):
     stack.add(parent.children[i])
   while stack.len > 0:
     let c = stack.pop()
-    yield c
+    # add children first, so that deleteContainer works on c
     for i in countdown(c.children.high, 0):
       stack.add(c.children[i])
+    yield c
 
 iterator containers*(pager: Pager): Container {.inline.} =
   if pager.container != nil:
     let root = getRoot(pager.container)
     yield root
-    for c in root.all_children:
+    for c in root.descendants:
       yield c
 
 proc setContainer*(pager: Pager, c: Container) {.jsfunc.} =
@@ -603,7 +605,7 @@ proc discardBuffer(pager: Pager, container = none(Container)) {.jsfunc.} =
 proc discardTree(pager: Pager, container = none(Container)) {.jsfunc.} =
   let container = container.get(pager.container)
   if container != nil:
-    for c in container.all_children:
+    for c in container.descendants:
       pager.deleteContainer(c)
   else:
     pager.alert("Buffer has no children!")