about summary refs log tree commit diff stats
path: root/src/local
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-16 20:42:58 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-16 20:44:51 +0100
commit3ba8a90c72c3dcc635eda57329d2dc6e950f9d2a (patch)
tree8605b54c0710d82daa55409dc2313ea3470679a8 /src/local
parent9aa8e20bd5552916c6b382659224f1003b02dbc7 (diff)
downloadchawan-3ba8a90c72c3dcc635eda57329d2dc6e950f9d2a.tar.gz
pager: fix disappearing buffers when reload fails
we do have logic for this in replace(), but it was not working because
setContainer changed the buffer too early.
Diffstat (limited to 'src/local')
-rw-r--r--src/local/pager.nim17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/local/pager.nim b/src/local/pager.nim
index 5c56643b..9ad854c4 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -728,6 +728,7 @@ proc deleteContainer(pager: Pager; container: Container) =
   if container.sourcepair != nil:
     container.sourcepair.sourcepair = nil
     container.sourcepair = nil
+  var setTarget: Container = nil
   if container.parent != nil:
     let parent = container.parent
     let n = parent.children.find(container)
@@ -737,29 +738,27 @@ proc deleteContainer(pager: Pager; container: Container) =
       child.parent = container.parent
       parent.children.insert(child, n + 1)
     parent.children.delete(n)
-    if container == pager.container:
-      if n == 0:
-        pager.setContainer(parent)
-      else:
-        pager.setContainer(parent.children[n - 1])
+    if n == 0:
+      setTarget = parent
+    else:
+      setTarget = parent.children[n - 1]
   elif container.children.len > 0:
     let parent = container.children[0]
     parent.parent = nil
     for i in 1..container.children.high:
       container.children[i].parent = parent
       parent.children.add(container.children[i])
-    if container == pager.container:
-      pager.setContainer(parent)
+    setTarget = parent
   else:
     for child in container.children:
       child.parent = nil
-    if container == pager.container:
-      pager.setContainer(nil)
   container.parent = nil
   container.children.setLen(0)
   if container.replace != nil:
     pager.replace(container, container.replace)
     container.replace = nil
+  elif pager.container == container:
+    pager.setContainer(setTarget)
   pager.unreg.add(container)
   if container.process != -1:
     pager.forkserver.removeChild(container.process)