diff options
author | bptato <nincsnevem662@gmail.com> | 2023-10-01 11:15:10 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-10-01 11:33:45 +0200 |
commit | 37792c785df6cc09411c19dbe7e2dd50a242755e (patch) | |
tree | c9f9d30e9e327625c53c58961f0dc3b3310b52cb /src | |
parent | b028afab5e583fb0166a1ba2030f3250208298d2 (diff) | |
download | chawan-37792c785df6cc09411c19dbe7e2dd50a242755e.tar.gz |
more vi/m compat
Diffstat (limited to 'src')
-rw-r--r-- | src/local/container.nim | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index 9667d84b..34d4d181 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -624,32 +624,42 @@ proc cursorPrevWord(container: Container) {.jsfunc.} = else: container.cursorLineBegin() -proc pageDown(container: Container) {.jsfunc.} = - container.setFromY(container.fromy + container.height) - container.setCursorY(container.cursory + container.height) +proc pageDown(container: Container, n = 1) {.jsfunc.} = + container.setFromY(container.fromy + container.height * n) + container.setCursorY(container.cursory + container.height * n) container.restoreCursorX() -proc pageUp(container: Container) {.jsfunc.} = - container.setFromY(container.fromy - container.height) - container.setCursorY(container.cursory - container.height) +proc pageUp(container: Container, n = 1) {.jsfunc.} = + container.setFromY(container.fromy - container.height * n) + container.setCursorY(container.cursory - container.height * n) container.restoreCursorX() -proc pageLeft(container: Container) {.jsfunc.} = - container.setFromX(container.fromx - container.width) +proc pageLeft(container: Container, n = 1) {.jsfunc.} = + container.setFromX(container.fromx - container.width * n) -proc pageRight(container: Container) {.jsfunc.} = - container.setFromX(container.fromx + container.width) +proc pageRight(container: Container, n = 1) {.jsfunc.} = + container.setFromX(container.fromx + container.width * n) -proc halfPageUp(container: Container) {.jsfunc.} = - container.setFromY(container.fromy - container.height div 2 + 1) - container.setCursorY(container.cursory - container.height div 2 + 1) +# I am not cloning the vi behavior here because it is counter-intuitive +# and annoying. +# Users who disagree are free to implement it themselves. (It is about +# 5 lines of JS.) +proc halfPageUp(container: Container, n = 1) {.jsfunc.} = + container.setFromY(container.fromy - (container.height div 2 + 1) * n) + container.setCursorY(container.cursory - (container.height div 2 + 1) * n) container.restoreCursorX() -proc halfPageDown(container: Container) {.jsfunc.} = - container.setFromY(container.fromy + container.height div 2 - 1) - container.setCursorY(container.cursory + container.height div 2 - 1) +proc halfPageDown(container: Container, n = 1) {.jsfunc.} = + container.setFromY(container.fromy + (container.height div 2 - 1) * n) + container.setCursorY(container.cursory + (container.height div 2 - 1) * n) container.restoreCursorX() +proc halfPageLeft(container: Container, n = 1) {.jsfunc.} = + container.setFromX(container.fromx - (container.width div 2 + 1) * n) + +proc halfPageRight(container: Container, n = 1) {.jsfunc.} = + container.setFromX(container.fromx + (container.width div 2 - 1) * n) + proc cursorFirstLine(container: Container) {.jsfunc.} = if container.select.open: container.select.cursorFirstLine() |