about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-05-25 15:25:10 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-05-25 15:25:10 -0700
commit9892bc5d7c924ce284003a35c00914352713eb42 (patch)
tree1f4d18454806f5acf7e1cc4a6f7dbae9dca9a885
parentcb943b9aeb8a5b152e20ee4934723156115b1454 (diff)
downloadlines.love-9892bc5d7c924ce284003a35c00914352713eb42.tar.gz
extract couple of functions
-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