diff options
author | bptato <nincsnevem662@gmail.com> | 2023-10-01 12:25:33 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-10-01 12:25:33 +0200 |
commit | 421eefcc7598bbe040f426ac93b0edbefcc437ba (patch) | |
tree | 60bc5738c2c3b17c4ad09a81492cd976651dea91 /src | |
parent | a30fe41cc3a964c50ebb30cb49e3e4bc80344d3f (diff) | |
download | chawan-421eefcc7598bbe040f426ac93b0edbefcc437ba.tar.gz |
Fix cursor x not being updated on backwards search
`refresh' does not correlate with the need of moving the cursor X position, `save' is a better choice.
Diffstat (limited to 'src')
-rw-r--r-- | src/local/container.nim | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index da13ce02..1d13ef68 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -415,7 +415,13 @@ proc setFromXY(container: Container, x, y: int) {.jsfunc.} = container.setFromY(y) container.setFromX(x) -proc setCursorX(container: Container, x: int, refresh = true, save = true) {.jsfunc.} = +# Set the cursor to the xth column. 0-based. +# * refresh = false inhibits reporting of the cursor position to the buffer. +# * save = false inhibits cursor movement if it is currently outside the +# screen, and makes it so cursorx is not saved for restoration on cursory +# movement. +proc setCursorX(container: Container, x: int, refresh = true, save = true) + {.jsfunc.} = if not container.lineLoaded(container.cursory): container.pos.setx = x container.pos.setxrefresh = refresh @@ -424,9 +430,11 @@ proc setCursorX(container: Container, x: int, refresh = true, save = true) {.jsf let cw = container.currentLineWidth() let x2 = x let x = max(min(x, cw - 1), 0) - if not refresh or container.fromx <= x and x < container.fromx + container.width: + # we check for save here, because it is only set by restoreCursorX where + # we do not want to move the cursor just because it is outside the window. + if not save or container.fromx <= x and x < container.fromx + container.width: container.pos.cursorx = x - elif refresh and container.fromx > x: + elif save and container.fromx > x: if x2 < container.cursorx: container.setFromX(x, false) container.pos.cursorx = container.fromx |