aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/buffer/buffer.nim3
-rw-r--r--src/buffer/container.nim16
-rw-r--r--src/html/htmlparser.nim16
3 files changed, 22 insertions, 13 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
diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim
index 123d8ac7..2b48c59d 100644
--- a/src/html/htmlparser.nim
+++ b/src/html/htmlparser.nim
@@ -977,6 +977,7 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode =
while true:
inc j
node = aboveNode
+ let nodeStackIndex = parser.openElements.find(node)
if node == formatting: break
var nodeFormattingIndex = -1
for i in countdown(parser.activeFormatting.high, 0):
@@ -987,27 +988,32 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode =
parser.activeFormatting.delete(nodeFormattingIndex)
if nodeFormattingIndex < bookmark:
dec bookmark # a previous node got deleted, so decrease bookmark by one
- let nodeStackIndex = parser.openElements.find(node)
if nodeFormattingIndex < 0:
+ aboveNode = parser.openElements[nodeStackIndex - 1]
parser.openElements.delete(nodeStackIndex)
if nodeStackIndex < furthestBlockIndex:
dec furthestBlockIndex
+ furthestBlock = parser.openElements[furthestBlockIndex]
continue
let element = parser.createElement(parser.activeFormatting[nodeFormattingIndex][1], Namespace.HTML, commonAncestor)
parser.activeFormatting[nodeFormattingIndex] = (element, parser.activeFormatting[nodeFormattingIndex][1])
- parser.openElements[nodeFormattingIndex] = element
- aboveNode = parser.openElements[nodeFormattingIndex - 1]
+ parser.openElements[nodeStackIndex] = element
+ aboveNode = parser.openElements[nodeStackIndex - 1]
node = element
if lastNode == furthestBlock:
- bookmark = nodeFormattingIndex
+ bookmark = nodeFormattingIndex + 1
node.append(lastNode)
lastNode = node
let location = parser.appropriatePlaceForInsert(commonAncestor)
location.inside.insert(lastNode, location.before)
let token = parser.activeFormatting[formattingIndex][1]
let element = parser.createElement(token, Namespace.HTML, furthestBlock)
- for child in furthestBlock.childNodes:
+ var tomove: seq[Node]
+ for j in countdown(furthestBlock.childNodes.high, 0):
+ let child = furthestBlock.childNodes[j]
child.remove()
+ tomove.add(child)
+ for child in tomove:
element.append(child)
furthestBlock.append(element)
parser.activeFormatting.insert((element, token), bookmark)