diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-06 15:05:05 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-06 21:08:14 +0100 |
commit | fb8bbaa65fa69a0a59d5d1fb6be93ab36cd4821a (patch) | |
tree | 4a015b9eb8c11835a1c7b2ba17d1a2300feba5f0 /src/buffer | |
parent | 7c1d00a6e5c723d101cf2f87991f14a8fc8d006f (diff) | |
download | chawan-fb8bbaa65fa69a0a59d5d1fb6be93ab36cd4821a.tar.gz |
Optimize sendCursorPosition/updateHover, close streams after loadResource
Diffstat (limited to 'src/buffer')
-rw-r--r-- | src/buffer/buffer.nim | 21 | ||||
-rw-r--r-- | src/buffer/container.nim | 19 |
2 files changed, 21 insertions, 19 deletions
diff --git a/src/buffer/buffer.nim b/src/buffer/buffer.nim index ae91be54..1048d7d2 100644 --- a/src/buffer/buffer.nim +++ b/src/buffer/buffer.nim @@ -462,11 +462,6 @@ proc updateHover*(buffer: Buffer, cursorx, cursory: int): UpdateHoverResult {.pr if i >= 0: thisnode = buffer.lines[cursory].formats[i].node let prevnode = buffer.prevnode - let title = thisnode.getTitle() - if title != "": - result.hover = some(title) - elif buffer.hovertext != "": - result.hover = some(buffer.hovertext) if thisnode != prevnode and (thisnode == nil or prevnode == nil or thisnode.node != prevnode.node): for styledNode in thisnode.branch: @@ -476,12 +471,19 @@ proc updateHover*(buffer: Buffer, cursorx, cursory: int): UpdateHoverResult {.pr elem.hover = true result.repaint = true - let link = thisnode.getLink() - if link != nil: + var upd = false + let title = thisnode.getTitle() + if title != "": + upd = true + buffer.hovertext = title + elif (let link = thisnode.getLink(); link != nil): + upd = true buffer.hovertext = link.href - result.hover = some(link.href) else: + upd = buffer.hovertext != "" buffer.hovertext = "" + if upd: + result.hover = some(buffer.hovertext) for styledNode in prevnode.branch: if styledNode.t == STYLED_ELEMENT and styledNode.node != nil: @@ -603,7 +605,7 @@ proc load*(buffer: Buffer): tuple[atend: bool, lines, bytes: int] {.proxy.} = buffer.readbufsize = min(BufferSize, buffer.readbufsize * 2) except IOError: # Presumably EAGAIN, unless the loader process crashed in which case we're screwed. - s = s.until('\0') + s = s.until('\0') #TODO this shouldn't be needed here... buffer.timeout = buffer.lasttimeout if buffer.readbufsize == 1: if buffer.lasttimeout == 0: @@ -880,6 +882,7 @@ type ClickResult* = object repaint*: bool proc click*(buffer: Buffer, cursorx, cursory: int): ClickResult {.proxy.} = + if buffer.lines.len <= cursory: return let clickable = buffer.getCursorClickable(cursorx, cursory) if clickable != nil: case clickable.tagType diff --git a/src/buffer/container.nim b/src/buffer/container.nim index 58e6d350..fdebb204 100644 --- a/src/buffer/container.nim +++ b/src/buffer/container.nim @@ -281,14 +281,11 @@ proc requestLines*(container: Container, w = container.lineWindow) = proc redraw*(container: Container) {.jsfunc.} = container.triggerEvent(ContainerEvent(t: UPDATE, force: true)) -proc sendCursorPosition*(container: Container) = +proc sendCursorPosition(container: Container) = container.iface.updateHover(container.cursorx, container.cursory).then(proc(res: UpdateHoverResult) = if res.hover.isSome: container.hovertext = res.hover.get container.triggerEvent(STATUS) - elif container.hovertext != "": - container.hovertext = "" - container.triggerEvent(STATUS) if res.repaint: container.needslines = true) @@ -298,12 +295,13 @@ proc setFromY*(container: Container, y: int) {.jsfunc.} = container.needslines = true container.triggerEvent(UPDATE) -proc setFromX*(container: Container, x: int) {.jsfunc.} = +proc setFromX*(container: Container, x: int, refresh = true) {.jsfunc.} = if container.pos.fromx != x: container.pos.fromx = max(min(x, container.maxfromx), 0) if container.pos.fromx > container.cursorx: container.pos.cursorx = min(container.pos.fromx, container.currentLineWidth()) - container.sendCursorPosition() + if refresh: + container.sendCursorPosition() container.triggerEvent(UPDATE) proc setFromXY*(container: Container, x, y: int) {.jsfunc.} = @@ -322,15 +320,16 @@ proc setCursorX*(container: Container, x: int, refresh = true, save = true) {.js container.pos.cursorx = x elif refresh and container.fromx > x: if x2 < container.cursorx: - container.setFromX(x) + container.setFromX(x, false) container.pos.cursorx = container.fromx elif x > container.cursorx: - container.setFromX(max(x - container.width + 1, container.fromx)) + container.setFromX(max(x - container.width + 1, container.fromx), false) container.pos.cursorx = x elif x < container.cursorx: - container.setFromX(x) + container.setFromX(x, false) container.pos.cursorx = x - container.sendCursorPosition() + if refresh: + container.sendCursorPosition() if save: container.pos.xend = container.cursorx |