aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-10-14 17:13:29 +0200
committerbptato <nincsnevem662@gmail.com>2023-10-14 17:16:14 +0200
commitc225ff1619c9db8a48160c4e82c82da91f133f4d (patch)
treeea8a3d4bbad7ddb0b7bed0d21cc726434aefa971 /src
parenteae438e48ad7c1558f07d539469ab55c9d67fac4 (diff)
downloadchawan-c225ff1619c9db8a48160c4e82c82da91f133f4d.tar.gz
container: add cursorNthLink, cursorRevNthLink
Diffstat (limited to 'src')
-rw-r--r--src/config/config.nim2
-rw-r--r--src/local/container.nim14
-rw-r--r--src/server/buffer.nim42
3 files changed, 53 insertions, 5 deletions
diff --git a/src/config/config.nim b/src/config/config.nim
index 871b4e3c..5f749708 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -587,7 +587,7 @@ proc parseConfig(config: Config, dir: string, t: TomlValue) =
when nimvm:
config.parseConfig(dir, staticRead(dir / s))
else:
- config.parseConfig(dir, newFileStream(dir / s))
+ config.parseConfig(dir, openFileExpand(dir, s))
config.configdir = dir
#TODO: for omnirule/siteconf, check if substitution rules are specified?
diff --git a/src/local/container.nim b/src/local/container.nim
index a04b8b88..e62a3cd4 100644
--- a/src/local/container.nim
+++ b/src/local/container.nim
@@ -802,6 +802,20 @@ proc cursorPrevLink*(container: Container) {.jsfunc.} =
if res.x > -1 and res.y != -1:
container.setCursorXYCenter(res.x, res.y))
+proc cursorNthLink*(container: Container, n = 1) {.jsfunc.} =
+ container.iface
+ .findNthLink(n)
+ .then(proc(res: tuple[x, y: int]) =
+ if res.x > -1 and res.y != -1:
+ container.setCursorXYCenter(res.x, res.y))
+
+proc cursorRevNthLink*(container: Container, n = 1) {.jsfunc.} =
+ container.iface
+ .findRevNthLink(n)
+ .then(proc(res: tuple[x, y: int]) =
+ if res.x > -1 and res.y != -1:
+ container.setCursorXYCenter(res.x, res.y))
+
proc clearSearchHighlights*(container: Container) =
for i in countdown(container.highlights.high, 0):
if container.highlights[i].clear:
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index 49ee97aa..5ed97258 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -65,10 +65,10 @@ type
BufferCommand* = enum
LOAD, RENDER, WINDOW_CHANGE, FIND_ANCHOR, READ_SUCCESS, READ_CANCELED,
- CLICK, FIND_NEXT_LINK, FIND_PREV_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
+ 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
# LOADING_PAGE: istream open
# LOADING_RESOURCES: istream closed, resources open
@@ -470,6 +470,40 @@ proc findNextLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr
inc i
return (-1, -1)
+proc findNthLink*(buffer: Buffer, i: int): tuple[x, y: int] {.proxy.} =
+ if i == 0:
+ return (-1, -1)
+ var k = 0
+ var link: Element
+ for y in 0 .. buffer.lines.high:
+ let line = buffer.lines[y]
+ for j in 0 ..< line.formats.len:
+ let format = line.formats[j]
+ let fl = format.node.getClickable()
+ if fl != nil and fl != link:
+ inc k
+ if k == i:
+ return (format.pos, y)
+ link = fl
+ return (-1, -1)
+
+proc findRevNthLink*(buffer: Buffer, i: int): tuple[x, y: int] {.proxy.} =
+ if i == 0:
+ return (-1, -1)
+ var k = 0
+ var link: Element
+ for y in countdown(buffer.lines.high, 0):
+ let line = buffer.lines[y]
+ for j in countdown(line.formats.high, 0):
+ let format = line.formats[j]
+ let fl = format.node.getClickable()
+ if fl != nil and fl != link:
+ inc k
+ if k == i:
+ return (format.pos, y)
+ link = fl
+ return (-1, -1)
+
proc findPrevMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int,
wrap: bool, n: int): BufferMatch {.proxy.} =
if cursory >= buffer.lines.len: return