about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-17 22:12:08 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-17 22:12:08 -0700
commit9a42128eb406fe90ee768f20469352eabbd0314f (patch)
tree8cce818a458bac3a3f7e475462126a373d218330
parent6c031fc1d0affdc41bd25ed5d8f6dbff399a3113 (diff)
downloadlines.love-9a42128eb406fe90ee768f20469352eabbd0314f.tar.gz
jump between lines on left/right
Also skip past drawings.
-rw-r--r--main.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/main.lua b/main.lua
index 93a97a9..96f56c7 100644
--- a/main.lua
+++ b/main.lua
@@ -275,12 +275,34 @@ function keychord_pressed(chord)
       Cursor_pos = 1
     end
   elseif chord == 'left' then
+    assert(Lines[Cursor_line].mode == 'text')
     if Cursor_pos > 1 then
       Cursor_pos = Cursor_pos-1
+    else
+      local new_cursor_line = Cursor_line
+      while new_cursor_line > 1 do
+        new_cursor_line = new_cursor_line-1
+        if Lines[new_cursor_line].mode == 'text' then
+          Cursor_line = new_cursor_line
+          Cursor_pos = #Lines[Cursor_line].data+1
+          break
+        end
+      end
     end
   elseif chord == 'right' then
+    assert(Lines[Cursor_line].mode == 'text')
     if Cursor_pos <= #Lines[Cursor_line].data then
       Cursor_pos = Cursor_pos+1
+    else
+      local new_cursor_line = Cursor_line
+      while new_cursor_line <= #Lines-1 do
+        new_cursor_line = new_cursor_line+1
+        if Lines[new_cursor_line].mode == 'text' then
+          Cursor_line = new_cursor_line
+          Cursor_pos = 1
+          break
+        end
+      end
     end
   elseif chord == 'home' then
     Cursor_pos = 1