about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-12-19 14:28:15 +0100
committerbptato <nincsnevem662@gmail.com>2021-12-19 14:28:20 +0100
commita91eec366dc18f73aa8e935920fc51c82831a01b (patch)
tree618969cf1bdd9f8e1c1549e961553a8305cf3dde /src/io
parent61f31f07c04081943382d94554b9eef5aaee1712 (diff)
downloadchawan-a91eec366dc18f73aa8e935920fc51c82831a01b.tar.gz
Add commands for vertical navigation on displayed line
Diffstat (limited to 'src/io')
-rw-r--r--src/io/buffer.nim16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index d212deac..2cdc1a77 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -479,6 +479,18 @@ proc cursorBottom*(buffer: Buffer) =
   buffer.cursory = min(buffer.fromy + buffer.height - 1, buffer.numLines - 1)
   buffer.restoreCursorX()
 
+proc cursorLeftEdge*(buffer: Buffer) =
+  buffer.cursorx = buffer.fromx
+  buffer.xend = buffer.cursorx
+
+proc cursorVertMiddle*(buffer: Buffer) =
+  buffer.cursorx = min(buffer.fromx + (buffer.width - 2) div 2, buffer.currentLineWidth)
+  buffer.xend = buffer.cursorx
+
+proc cursorRightEdge*(buffer: Buffer) =
+  buffer.cursorx = min(buffer.fromx + buffer.width - 1, buffer.currentLineWidth)
+  buffer.xend = buffer.cursorx
+
 proc centerLine*(buffer: Buffer) =
   let ny = max(min(buffer.cursory - buffer.height div 2, buffer.numLines - buffer.height), 0)
   if ny != buffer.fromy:
@@ -694,7 +706,6 @@ proc renderPlainText*(buffer: Buffer, text: string) =
   var i = 0
   var x = 0
   var y = 0
-  var r: Rune
   var af = false
   while i < text.len:
     if text[i] == '\n':
@@ -844,6 +855,9 @@ proc inputLoop(attrs: TermAttributes, buffer: Buffer): bool =
     of ACTION_CURSOR_TOP: buffer.cursorTop()
     of ACTION_CURSOR_MIDDLE: buffer.cursorMiddle()
     of ACTION_CURSOR_BOTTOM: buffer.cursorBottom()
+    of ACTION_CURSOR_LEFT_EDGE: buffer.cursorLeftEdge()
+    of ACTION_CURSOR_VERT_MIDDLE: buffer.cursorVertMiddle()
+    of ACTION_CURSOR_RIGHT_EDGE: buffer.cursorRightEdge()
     of ACTION_CENTER_LINE: buffer.centerLine()
     of ACTION_SCROLL_DOWN: buffer.scrollDown()
     of ACTION_SCROLL_UP: buffer.scrollUp()