diff options
author | bptato <nincsnevem662@gmail.com> | 2023-09-26 16:52:57 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-09-26 16:54:46 +0200 |
commit | 2b47c6f5ac8d41a8025c10d02da4d6090e616a68 (patch) | |
tree | e97afd43206d14b058813d159dc1f53c59b8f20b /src/server | |
parent | ee17e946c53e6ca807dea2df04f8f2b9eedd754f (diff) | |
download | chawan-2b47c6f5ac8d41a8025c10d02da4d6090e616a68.tar.gz |
Add precnum support to more functions
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/buffer.nim | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 4ab09c20..d6c00ef9 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -463,16 +463,20 @@ proc findNextLink*(buffer: Buffer, cursorx, cursory: int): tuple[x, y: int] {.pr inc i return (-1, -1) -proc findPrevMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int, wrap: bool): BufferMatch {.proxy.} = +proc findPrevMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int, + wrap: bool, n: int): BufferMatch {.proxy.} = if cursory >= buffer.lines.len: return var y = cursory let b = buffer.cursorBytes(y, cursorx) let res = regex.exec(buffer.lines[y].str, 0, b) + var numfound = 0 if res.success and res.captures.len > 0: let cap = res.captures[^1] let x = buffer.lines[y].str.width(0, cap.s) let str = buffer.lines[y].str.substr(cap.s, cap.e - 1) - return BufferMatch(success: true, x: x, y: y, str: str) + inc numfound + if numfound >= n: + return BufferMatch(success: true, x: x, y: y, str: str) dec y while true: if y < 0: @@ -485,21 +489,27 @@ proc findPrevMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int, wrap: b let cap = res.captures[^1] let x = buffer.lines[y].str.width(0, cap.s) let str = buffer.lines[y].str.substr(cap.s, cap.e - 1) - return BufferMatch(success: true, x: x, y: y, str: str) + inc numfound + if numfound >= n: + return BufferMatch(success: true, x: x, y: y, str: str) if y == cursory: break dec y -proc findNextMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int, wrap: bool): BufferMatch {.proxy.} = +proc findNextMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int, + wrap: bool, n: int): BufferMatch {.proxy.} = if cursory >= buffer.lines.len: return var y = cursory let b = buffer.cursorBytes(y, cursorx + 1) let res = regex.exec(buffer.lines[y].str, b, buffer.lines[y].str.len) + var numfound = 0 if res.success and res.captures.len > 0: let cap = res.captures[0] let x = buffer.lines[y].str.width(0, cap.s) let str = buffer.lines[y].str.substr(cap.s, cap.e - 1) - return BufferMatch(success: true, x: x, y: y, str: str) + inc numfound + if numfound >= n: + return BufferMatch(success: true, x: x, y: y, str: str) inc y while true: if y > buffer.lines.high: @@ -512,7 +522,9 @@ proc findNextMatch*(buffer: Buffer, regex: Regex, cursorx, cursory: int, wrap: b let cap = res.captures[0] let x = buffer.lines[y].str.width(0, cap.s) let str = buffer.lines[y].str.substr(cap.s, cap.e - 1) - return BufferMatch(success: true, x: x, y: y, str: str) + inc numfound + if numfound >= n: + return BufferMatch(success: true, x: x, y: y, str: str) if y == cursory: break inc y |