about summary refs log tree commit diff stats
path: root/src/buffer
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-11-27 16:41:05 +0100
committerbptato <nincsnevem662@gmail.com>2022-11-27 16:46:42 +0100
commitfddc8d8da34b2f05b99d56b3c753a7b00d54ae7c (patch)
tree0d014c2c76b038ad7ac68d9745454c3244426993 /src/buffer
parent3a12afa7617f3ccecbbf6b5852da3d6382a412bb (diff)
downloadchawan-fddc8d8da34b2f05b99d56b3c753a7b00d54ae7c.tar.gz
Fix adoption agency algorithm bugs
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/buffer.nim3
-rw-r--r--src/buffer/container.nim16
2 files changed, 11 insertions, 8 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim
index a2860952..34831795 100644
--- a/src/buffer/buffer.nim
+++ b/src/buffer/buffer.nim
@@ -595,9 +595,6 @@ proc finishLoad(buffer: Buffer) =
     buffer.document = parseHTML5(buffer.sstream)
     buffer.document.location = buffer.location
     buffer.loadResources(buffer.document)
-    buffer.do_reshape()
-  else:
-    buffer.do_reshape()
   buffer.selector.unregister(int(buffer.getFd()))
   buffer.istream.close()
   buffer.streamclosed = true
diff --git a/src/buffer/container.nim b/src/buffer/container.nim
index 58f93f42..eae3e3d1 100644
--- a/src/buffer/container.nim
+++ b/src/buffer/container.nim
@@ -564,22 +564,29 @@ proc setLoadInfo(container: Container, msg: string) =
   container.loadinfo = msg
   container.triggerEvent(STATUS)
 
+proc setNumLines(container: Container, lines: int) =
+  container.numLines = lines
+  container.updateCursor()
+
 proc load*(container: Container) =
   container.setLoadInfo("Connecting to " & $container.source.location & "...")
   var onload: (proc(res: tuple[atend: bool, lines, bytes: int]))
   onload = (proc(res: tuple[atend: bool, lines, bytes: int]) =
-    if res.bytes == -1:
+    if res.bytes == -1 or res.atend:
       container.setLoadInfo("")
     elif not res.atend:
       container.setLoadInfo(convert_size(res.bytes) & " loaded")
     if res.lines > container.numLines:
-      container.numLines = res.lines
+      container.setNumLines(res.lines)
       container.triggerEvent(STATUS)
       container.requestLines()
     if not res.atend and not container.canceled:
       discard container.iface.load().then(onload)
     elif not container.canceled:
-      container.iface.gotoAnchor().then(proc(res: tuple[x, y: int]) =
+      container.iface.render().then(proc(lines: int): auto =
+        container.setNumLines(lines)
+        return container.iface.gotoAnchor()
+      ).then(proc(res: tuple[x, y: int]) =
         if res.x != -1 and res.y != -1:
           container.setCursorXY(res.x, res.y)
       )
@@ -624,8 +631,7 @@ proc readSuccess*(container: Container, s: string) =
 
 proc reshape*(container: Container, noreq = false) {.jsfunc.} =
   container.iface.render().then(proc(lines: int) =
-    container.numLines = lines
-    container.updateCursor())
+    container.setNumLines(lines))
   if not noreq:
     container.needslines = true