diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/local/container.nim | 14 | ||||
-rw-r--r-- | src/server/buffer.nim | 21 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index 2a0051e6..7cb67862 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -850,6 +850,20 @@ proc cursorPrevLink*(container: Container) {.jsfunc.} = if res.x > -1 and res.y != -1: container.setCursorXYCenter(res.x, res.y)) +proc cursorNextParagraph*(container: Container, n = 1) {.jsfunc.} = + container.iface + .findNextParagraph(container.cursory, n) + .then(proc(res: int) = + container.setCursorY(res) + ) + +proc cursorPrevParagraph*(container: Container, n = 1) {.jsfunc.} = + container.iface + .findPrevParagraph(container.cursory, n) + .then(proc(res: int) = + container.setCursorY(res) + ) + proc cursorNthLink*(container: Container, n = 1) {.jsfunc.} = container.iface .findNthLink(n) diff --git a/src/server/buffer.nim b/src/server/buffer.nim index e69af1fb..fff6f195 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -68,7 +68,8 @@ type CLICK, FIND_NEXT_LINK, FIND_PREV_LINK, FIND_NTH_LINK, FIND_REV_NTH_LINK, FIND_NEXT_MATCH, FIND_PREV_MATCH, GET_SOURCE, GET_LINES, UPDATE_HOVER, PASS_FD, CONNECT, CONNECT2, GOTO_ANCHOR, CANCEL, GET_TITLE, SELECT, - REDIRECT_TO_FD, READ_FROM_FD, SET_CONTENT_TYPE, CLONE + REDIRECT_TO_FD, READ_FROM_FD, SET_CONTENT_TYPE, CLONE, FIND_PREV_PARAGRAPH, + FIND_NEXT_PARAGRAPH # LOADING_PAGE: istream open # LOADING_RESOURCES: istream closed, resources open @@ -477,6 +478,24 @@ proc findNextLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr inc i return (-1, -1) +proc findPrevParagraph*(buffer: Buffer, cursory, n: int): int {.proxy.} = + var y = cursory + for i in 0 ..< n: + while y >= 0 and buffer.lines[y].str.onlyWhitespace(): + dec y + while y >= 0 and not buffer.lines[y].str.onlyWhitespace(): + dec y + return y + +proc findNextParagraph*(buffer: Buffer, cursory, n: int): int {.proxy.} = + var y = cursory + for i in 0 ..< n: + while y < buffer.lines.len and buffer.lines[y].str.onlyWhitespace(): + inc y + while y < buffer.lines.len and not buffer.lines[y].str.onlyWhitespace(): + inc y + return y + proc findNthLink*(buffer: Buffer, i: int): tuple[x, y: int] {.proxy.} = if i == 0: return (-1, -1) |