aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-09 22:56:29 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-09 22:56:29 +0200
commit1c6891331b691a1fc3f2c71d333b235507e47ddb (patch)
tree3ec0f5d98f634d98b18f034c4e180229d0b70b50
parent6943546078a20c763a9bb346b42681efc0d1e527 (diff)
downloadchawan-1c6891331b691a1fc3f2c71d333b235507e47ddb.tar.gz
container: accept numbers in cursorLeft, cursorRight, etc.
These functions now take a numeric argument to determine how many cells/lines to move. Also, update the default config so e.g. 9j now works.
-rw-r--r--doc/config.md18
-rw-r--r--res/config.toml16
-rw-r--r--src/buffer/container.nim16
3 files changed, 25 insertions, 25 deletions
diff --git a/doc/config.md b/doc/config.md
index 8ee7c07c..114a8152 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -612,22 +612,22 @@ Note: this does not suspend buffer processes.</td>
</tr>
<tr>
-<td>`pager.cursorUp()`</td>
-<td>Move the cursor to the previous line.</td>
+<td>`pager.cursorUp(n = 1)`</td>
+<td>Move the cursor upwards by n lines, or if n is unspecified, by 1.</td>
</tr>
<tr>
-<td>`pager.cursorDown()`</td>
-<td>Move cursor to the next line.</td>
+<td>`pager.cursorDown(n = 1)`</td>
+<td>Move the cursor downwards by n lines, or if n is unspecified, by 1.</td>
</tr>
<tr>
-<td>`pager.cursorLeft()`</td>
-<td>Move the cursor to the previous cell.</td>
+<td>`pager.cursorLeft(n = 1)`</td>
+<td>Move the cursor to the left by n cells, or if n is unspecified, by 1.</td>
</tr>
<tr>
-<td>`pager.cursorRight()`</td>
-<td>Move the cursor to the next cell.</td>
+<td>`pager.cursorRight(n = 1)`</td>
+<td>Move the cursor to the right by n cells, or if n is unspecified, by 1.</td>
</tr>
<tr>
@@ -843,7 +843,7 @@ open the current buffer's contents as HTML.</td>
</tr>
<tr>
-<td>`pager.gotoLine()`</td>
+<td>`pager.gotoLine(n?)`</td>
<td>Go to the line passed as the first argument.<br>
If no arguments were specified, an input window for entering a line is
shown.</td>
diff --git a/res/config.toml b/res/config.toml
index d84f9b69..4e56761a 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -62,14 +62,14 @@ substitute-url = '(x) => "https://lite.duckduckgo.com/lite/?kp=-1&kd=-1&q=" + en
[page]
q = 'quit()'
C-z = 'suspend()'
-h = 'pager.cursorLeft()'
-j = 'pager.cursorDown()'
-k = 'pager.cursorUp()'
-l = 'pager.cursorRight()'
-'M-[D' = 'pager.cursorLeft()'
-'M-[B' = 'pager.cursorDown()'
-'M-[A' = 'pager.cursorUp()'
-'M-[C' = 'pager.cursorRight()'
+h = 'n => pager.cursorLeft(n ?? 1)'
+j = 'n => pager.cursorDown(n ?? 1)'
+k = 'n => pager.cursorUp(n ?? 1)'
+l = 'n => pager.cursorRight(n ?? 1)'
+'M-[D' = 'n => pager.cursorLeft(n ?? 1)'
+'M-[B' = 'n => pager.cursorDown(n ?? 1)'
+'M-[A' = 'n => pager.cursorUp(n ?? 1)'
+'M-[C' = 'n => pager.cursorRight(n ?? 1)'
'0' = 'pager.cursorLineBegin()'
'^' = 'pager.cursorLineTextStart()'
'$' = 'pager.cursorLineEnd()'
diff --git a/src/buffer/container.nim b/src/buffer/container.nim
index edba490f..53be817a 100644
--- a/src/buffer/container.nim
+++ b/src/buffer/container.nim
@@ -424,29 +424,29 @@ proc setCursorXY(container: Container, x, y: int, refresh = true) {.jsfunc.} =
if fy != container.fromy:
container.centerLine()
-proc cursorDown(container: Container) {.jsfunc.} =
+proc cursorDown(container: Container, n = 1) {.jsfunc.} =
if container.select.open:
container.select.cursorDown()
else:
- container.setCursorY(container.cursory + 1)
+ container.setCursorY(container.cursory + n)
-proc cursorUp(container: Container) {.jsfunc.} =
+proc cursorUp(container: Container, n = 1) {.jsfunc.} =
if container.select.open:
container.select.cursorUp()
else:
- container.setCursorY(container.cursory - 1)
+ container.setCursorY(container.cursory - n)
-proc cursorLeft(container: Container) {.jsfunc.} =
+proc cursorLeft(container: Container, n = 1) {.jsfunc.} =
if container.select.open:
container.select.cursorLeft()
else:
- container.setCursorX(container.cursorFirstX() - 1)
+ container.setCursorX(container.cursorFirstX() - n)
-proc cursorRight(container: Container) {.jsfunc.} =
+proc cursorRight(container: Container, n = 1) {.jsfunc.} =
if container.select.open:
container.select.cursorRight()
else:
- container.setCursorX(container.cursorLastX() + 1)
+ container.setCursorX(container.cursorLastX() + n)
proc cursorLineBegin(container: Container) {.jsfunc.} =
container.setCursorX(0)