about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-08 17:21:35 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-08 17:26:53 +0200
commit099550625e55ad59a6ed6bef54ad0d86470cdd91 (patch)
treede3fc24858cfc3450ad7fe719c96725b21d692ea
parentbf5f9d42fb90c2d8b989e73ffe051cf62a865be1 (diff)
downloadchawan-099550625e55ad59a6ed6bef54ad0d86470cdd91.tar.gz
container: add separate commands for 0 and ^
Just as in vi, 0 puts the cursor at the beginning of the current line,
and ^ puts the cursor at the position of the first non-blank character.
-rw-r--r--doc/config.md5
-rw-r--r--res/config.toml3
-rw-r--r--src/buffer/container.nim9
3 files changed, 16 insertions, 1 deletions
diff --git a/doc/config.md b/doc/config.md
index 0f986de4..cde6b1f4 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -584,6 +584,11 @@ Note: this does not suspend buffer processes.</td>
 </tr>
 
 <tr>
+<td>`pager.cursorLineTextStart()`</td>
+<td>Move the cursor to the first non-blank character of the line.</td>
+</tr>
+
+<tr>
 <td>`pager.cursorLineEnd()`</td>
 <td>Move the cursor to the last cell of the line.</td>
 </tr>
diff --git a/res/config.toml b/res/config.toml
index 88e4e775..b96f05d8 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -67,7 +67,8 @@ l = 'pager.cursorRight()'
 'M-[B' = 'pager.cursorDown()'
 'M-[A' = 'pager.cursorUp()'
 'M-[C' = 'pager.cursorRight()'
-'^' = 'pager.cursorLineBegin()'
+'0' = 'pager.cursorLineBegin()'
+'^' = 'pager.cursorLineTextStart()'
 '$' = 'pager.cursorLineEnd()'
 b = 'pager.cursorPrevWord()'
 w = 'pager.cursorNextWord()'
diff --git a/src/buffer/container.nim b/src/buffer/container.nim
index 143c169b..0e31b672 100644
--- a/src/buffer/container.nim
+++ b/src/buffer/container.nim
@@ -447,6 +447,15 @@ proc cursorRight(container: Container) {.jsfunc.} =
 proc cursorLineBegin(container: Container) {.jsfunc.} =
   container.setCursorX(0)
 
+proc cursorLineTextStart(container: Container) {.jsfunc.} =
+  if container.numLines == 0: return
+  var x = 0
+  for r in container.currentLine.runes:
+    if not r.isWhitespace():
+      break
+    x += r.twidth(x)
+  container.setCursorX(x)
+
 proc cursorLineEnd(container: Container) {.jsfunc.} =
   container.setCursorX(container.currentLineWidth() - 1)