aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-09 16:36:40 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-09 16:38:30 +0100
commit4aa3e24199f0aac97d5541adcbf1ae137f7b64f0 (patch)
tree807746ba02260f40362fbad3a3d5a3a42ea1a274 /src
parent6a1b1a2edfc6adf3d1d1a1aaa2c9fd95eccc8ff7 (diff)
downloadchawan-4aa3e24199f0aac97d5541adcbf1ae137f7b64f0.tar.gz
pager: add precnum to [, ]
Diffstat (limited to 'src')
-rw-r--r--src/local/container.nim8
-rw-r--r--src/server/buffer.nim32
2 files changed, 27 insertions, 13 deletions
diff --git a/src/local/container.nim b/src/local/container.nim
index 7cb67862..2f54a3e4 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -836,16 +836,16 @@ proc copyCursorPos*(container, c2: Container) =
container.startpos = some(c2.pos)
container.hasstart = true
-proc cursorNextLink*(container: Container) {.jsfunc.} =
+proc cursorNextLink*(container: Container, n = 1) {.jsfunc.} =
container.iface
- .findNextLink(container.cursorx, container.cursory)
+ .findNextLink(container.cursorx, container.cursory, n)
.then(proc(res: tuple[x, y: int]) =
if res.x > -1 and res.y != -1:
container.setCursorXYCenter(res.x, res.y))
-proc cursorPrevLink*(container: Container) {.jsfunc.} =
+proc cursorPrevLink*(container: Container, n = 1) {.jsfunc.} =
container.iface
- .findPrevLink(container.cursorx, container.cursory)
+ .findPrevLink(container.cursorx, container.cursory, n)
.then(proc(res: tuple[x, y: int]) =
if res.x > -1 and res.y != -1:
container.setCursorXYCenter(res.x, res.y))
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index fff6f195..cdbfc16b 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -385,8 +385,10 @@ proc navigate(buffer: Buffer, url: URL) =
#TODO how?
stderr.write("navigate to " & $url & "\n")
-proc findPrevLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.proxy.} =
+proc findPrevLink*(buffer: Buffer, cursorx, cursory, n: int):
+ tuple[x, y: int] {.proxy.} =
if cursory >= buffer.lines.len: return (-1, -1)
+ var found = 0
let line = buffer.lines[cursory]
var i = line.findFormatN(cursorx) - 1
var link: Element = nil
@@ -430,13 +432,19 @@ proc findPrevLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr
# an efficient and correct way to do this.
break
+ template found_pos(x, y: int, fl: Element) =
+ inc found
+ link = fl
+ if found == n:
+ return (x, y)
+
while i >= 0:
let format = line.formats[i]
let fl = format.node.getClickable()
if fl != nil and fl != link:
let y = cursory
link_beginning
- return (lx, ly)
+ found_pos lx, ly, fl
dec i
for y in countdown(cursory - 1, 0):
@@ -447,11 +455,12 @@ proc findPrevLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr
let fl = format.node.getClickable()
if fl != nil and fl != link:
link_beginning
- return (lx, ly)
+ found_pos lx, ly, fl
dec i
return (-1, -1)
-proc findNextLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.proxy.} =
+proc findNextLink*(buffer: Buffer, cursorx, cursory, n: int):
+ tuple[x, y: int] {.proxy.} =
if cursory >= buffer.lines.len: return (-1, -1)
let line = buffer.lines[cursory]
var i = line.findFormatN(cursorx) - 1
@@ -460,22 +469,27 @@ proc findNextLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr
link = line.formats[i].node.getClickable()
inc i
+ var found = 0
+ template found_pos(x, y: int, fl: Element) =
+ inc found
+ link = fl
+ if found == n:
+ return (x, y)
+
while i < line.formats.len:
let format = line.formats[i]
let fl = format.node.getClickable()
if fl != nil and fl != link:
- return (format.pos, cursory)
+ found_pos format.pos, cursory, fl
inc i
for y in (cursory + 1)..(buffer.lines.len - 1):
let line = buffer.lines[y]
- i = 0
- while i < line.formats.len:
+ for i in 0 ..< line.formats.len:
let format = line.formats[i]
let fl = format.node.getClickable()
if fl != nil and fl != link:
- return (format.pos, y)
- inc i
+ found_pos format.pos, y, fl
return (-1, -1)
proc findPrevParagraph*(buffer: Buffer, cursory, n: int): int {.proxy.} =