about summary refs log tree commit diff stats
path: root/text.lua
diff options
context:
space:
mode:
Diffstat (limited to 'text.lua')
-rw-r--r--text.lua76
1 files changed, 42 insertions, 34 deletions
diff --git a/text.lua b/text.lua
index a0cec1c..7ff7baf 100644
--- a/text.lua
+++ b/text.lua
@@ -769,41 +769,9 @@ function Text.keychord_pressed(chord)
     Text.insert_at_cursor('\t')
     save_to_disk(Lines, Filename)
   elseif chord == 'left' then
-    assert(Lines[Cursor1.line].mode == 'text')
-    if Cursor1.pos > 1 then
-      Cursor1.pos = Cursor1.pos-1
-    else
-      local new_cursor_line = Cursor1.line
-      while new_cursor_line > 1 do
-        new_cursor_line = new_cursor_line-1
-        if Lines[new_cursor_line].mode == 'text' then
-          Cursor1.line = new_cursor_line
-          Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
-          break
-        end
-      end
-      if Cursor1.line < Screen_top1.line then
-        Screen_top1.line = Cursor1.line
-      end
-    end
+    Text.left()
   elseif chord == 'right' then
-    assert(Lines[Cursor1.line].mode == 'text')
-    if Cursor1.pos <= utf8.len(Lines[Cursor1.line].data) then
-      Cursor1.pos = Cursor1.pos+1
-    else
-      local new_cursor_line = Cursor1.line
-      while new_cursor_line <= #Lines-1 do
-        new_cursor_line = new_cursor_line+1
-        if Lines[new_cursor_line].mode == 'text' then
-          Cursor1.line = new_cursor_line
-          Cursor1.pos = 1
-          break
-        end
-      end
-      if Cursor1.line > Screen_bottom1.line then
-        Screen_top1.line = Cursor1.line
-      end
-    end
+    Text.right()
   elseif chord == 'home' then
     Cursor1.pos = 1
   elseif chord == 'end' then
@@ -957,6 +925,46 @@ function Text.keychord_pressed(chord)
   end
 end
 
+function Text.left()
+  assert(Lines[Cursor1.line].mode == 'text')
+  if Cursor1.pos > 1 then
+    Cursor1.pos = Cursor1.pos-1
+  else
+    local new_cursor_line = Cursor1.line
+    while new_cursor_line > 1 do
+      new_cursor_line = new_cursor_line-1
+      if Lines[new_cursor_line].mode == 'text' then
+        Cursor1.line = new_cursor_line
+        Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
+        break
+      end
+    end
+    if Cursor1.line < Screen_top1.line then
+      Screen_top1.line = Cursor1.line
+    end
+  end
+end
+
+function Text.right()
+  assert(Lines[Cursor1.line].mode == 'text')
+  if Cursor1.pos <= utf8.len(Lines[Cursor1.line].data) then
+    Cursor1.pos = Cursor1.pos+1
+  else
+    local new_cursor_line = Cursor1.line
+    while new_cursor_line <= #Lines-1 do
+      new_cursor_line = new_cursor_line+1
+      if Lines[new_cursor_line].mode == 'text' then
+        Cursor1.line = new_cursor_line
+        Cursor1.pos = 1
+        break
+      end
+    end
+    if Cursor1.line > Screen_bottom1.line then
+      Screen_top1.line = Cursor1.line
+    end
+  end
+end
+
 function Text.pos_at_start_of_cursor_screen_line()
   if Lines[Cursor1.line].screen_line_starting_pos == nil then
     return 1,1