about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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