diff options
author | bptato <nincsnevem662@gmail.com> | 2022-06-17 19:06:46 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-06-17 19:06:46 +0200 |
commit | 571a539d88e72587ea070e685442d32609f050cb (patch) | |
tree | cce3475e29f0d6b566c4608aed91e49dd0eca701 /src/io/buffer.nim | |
parent | 4d2f3c55f7e880814c1d05a6e1137df63374a1b1 (diff) | |
download | chawan-571a539d88e72587ea070e685442d32609f050cb.tar.gz |
Fix cursorPrevLink
Diffstat (limited to 'src/io/buffer.nim')
-rw-r--r-- | src/io/buffer.nim | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim index e3858908..654bdbe7 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -515,11 +515,41 @@ proc cursorPrevLink*(buffer: Buffer) = link = line.formats[i].node.getClickable() dec i + var ly = 0 #last y + var lx = 0 #last x + template link_beginning() = + #go to beginning of link + ly = y #last y + lx = format.pos #last x + + #on the current line + let line = buffer.lines[y] + while i >= 0: + let format = line.formats[i] + let nl = format.node.getClickable() + if nl == fl: + lx = format.pos + dec i + + #on previous lines + for iy in countdown(ly - 1, 0): + let line = buffer.lines[iy] + i = line.formats.len - 1 + while i >= 0: + let format = line.formats[i] + let nl = format.node.getClickable() + if nl == fl: + ly = iy + lx = format.pos + dec i + while i >= 0: let format = line.formats[i] let fl = format.node.getClickable() if fl != nil and fl != link: - buffer.setCursorX(format.pos) + let y = buffer.cursory + link_beginning + buffer.setCursorXY(lx, ly) return dec i @@ -530,19 +560,7 @@ proc cursorPrevLink*(buffer: Buffer) = let format = line.formats[i] let fl = format.node.getClickable() if fl != nil and fl != link: - #go to beginning of link - var ly = y #last y - var lx = format.pos #last x - for iy in countdown(ly - 1, 0): - let line = buffer.lines[iy] - i = line.formats.len - 1 - while i >= 0: - let format = line.formats[i] - let nl = format.node.getClickable() - if nl == fl: - ly = iy - lx = format.pos - dec i + link_beginning buffer.setCursorXY(lx, ly) return dec i |