aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-10-01 11:15:10 +0200
committerbptato <nincsnevem662@gmail.com>2023-10-01 11:33:45 +0200
commit37792c785df6cc09411c19dbe7e2dd50a242755e (patch)
treec9f9d30e9e327625c53c58961f0dc3b3310b52cb
parentb028afab5e583fb0166a1ba2030f3250208298d2 (diff)
downloadchawan-37792c785df6cc09411c19dbe7e2dd50a242755e.tar.gz
more vi/m compat
-rw-r--r--doc/config.md34
-rw-r--r--res/chawan.html2
-rw-r--r--res/config.toml22
-rw-r--r--src/local/container.nim42
4 files changed, 62 insertions, 38 deletions
diff --git a/doc/config.md b/doc/config.md
index 1140f8d9..7af5d5db 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -713,33 +713,43 @@ Note: this does not suspend buffer processes.</td>
</tr>
<tr>
-<td>`pager.pageDown()`</td>
-<td>Scroll down by one page.</td>
+<td>`pager.pageDown(n = 1)`</td>
+<td>Scroll down by n pages.</td>
</tr>
<tr>
-<td>`pager.pageUp()`</td>
-<td>Scroll up by one page.</td>
+<td>`pager.pageUp(n = 1)`</td>
+<td>Scroll up by n pages.</td>
</tr>
<tr>
-<td>`pager.pageLeft()`</td>
-<td>Scroll to the left by one page.</td>
+<td>`pager.pageLeft(n = 1)`</td>
+<td>Scroll to the left by n pages.</td>
</tr>
<tr>
-<td>`pager.pageRight()`</td>
-<td>Scroll to the right by one page.</td>
+<td>`pager.pageRight(n = 1)`</td>
+<td>Scroll to the right n pages.</td>
</tr>
<tr>
-<td>`pager.halfPageDown()`</td>
-<td>Scroll forwards by half a page.</td>
+<td>`pager.halfPageDown(n = 1)`</td>
+<td>Scroll forwards by n half pages.</td>
</tr>
<tr>
-<td>`pager.halfPageUp()`</td>
-<td>Scroll backwards by half a page.</td>
+<td>`pager.halfPageUp(n = 1)`</td>
+<td>Scroll backwards by n half pages.</td>
+</tr>
+
+<tr>
+<td>`pager.halfPageLeft(n = 1)`</td>
+<td>Scroll to the left by n half pages.</td>
+</tr>
+
+<tr>
+<td>`pager.halfPageUp(n = 1)`</td>
+<td>Scroll to the right by n half pages.</td>
</tr>
<tr>
diff --git a/res/chawan.html b/res/chawan.html
index b73a4347..4bf6fc11 100644
--- a/res/chawan.html
+++ b/res/chawan.html
@@ -39,7 +39,7 @@ the meta key may be called Alt or Escape.)
<li><b>[</b>, <b>]</b>: move cursor to the previous/next hyperlink
<li><b>C-d</b>, <b>C-u</b>: scroll up/down by half a page
<li><b>C-f</b>, <b>C-b</b> (or <b>PgDn</b>, <b>PgUp</b>)</b>: scroll up/down by an entire page
-<li><b>(, )</b>: shift screen to the left/right by one cell
+<li><b>(, ) (or <b>zh</b>, <b>zl</b>): shift screen to the left/right by one cell
<li><b>&lt;, &gt;</b>: shift screen to the left/right by one page
<li><b>/</b>, <b>?</b>: search (or search backwards)
<li><b>n, N</b>: next/previous match
diff --git a/res/config.toml b/res/config.toml
index fed898e9..0b3536a8 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -89,16 +89,20 @@ L = 'n => pager.cursorBottom(n)'
';' = 'pager.cursorLeftEdge()'
'+' = 'pager.cursorMiddleColumn()'
'@' = 'pager.cursorRightEdge()'
-C-d = 'pager.halfPageDown()'
-C-u = 'pager.halfPageUp()'
-C-f = 'pager.pageDown()'
-C-b = 'pager.pageUp()'
-'M-[6~' = 'pager.pageDown()'
-'M-[5~' = 'pager.pageUp()'
-'>' = 'pager.pageRight()'
-'<' = 'pager.pageLeft()'
+C-d = 'n => pager.halfPageDown(n)'
+C-u = 'n => pager.halfPageUp(n)'
+C-f = 'n => pager.pageDown(n)'
+C-b = 'n => pager.pageUp(n)'
+'M-[6~' = 'n => pager.pageDown(n)'
+'M-[5~' = 'n => pager.pageUp(n)'
+'zH'= 'n => pager.pageLeft(n)'
+'zL' = 'n => pager.pageRight(n)'
+'<' = 'n => pager.pageLeft(n)'
+'>' = 'n => pager.pageRight(n)'
C-e = 'n => pager.scrollDown(n)'
C-y = 'n => pager.scrollUp(n)'
+'zh'= 'n => pager.scrollLeft(n)'
+'zl' = 'n => pager.scrollRight(n)'
J = 'n => pager.scrollDown(n)'
K = 'n => pager.scrollUp(n)'
'('= 'n => pager.scrollLeft(n)'
@@ -113,7 +117,7 @@ U = 'pager.reload()'
r = 'pager.redraw()'
R = 'pager.reshape()'
M-C-c = 'pager.cancel()'
-gg = 'pager.cursorFirstLine()'
+gg = 'n => n ? pager.gotoLine(n) : pager.cursorFirstLine()'
G = 'n => n ? pager.gotoLine(n) : pager.cursorLastLine()'
M-g = 'pager.gotoLine()'
'z.' = 'n => pager.centerLineBegin(n)'
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()