about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-08-17 09:51:17 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-08-17 09:51:17 -0700
commit03f3034930f7ac37a23cf6353f0a662e8967f200 (patch)
treee3d2023cacb02799e802e079a4c2fe336e87b0b4
parentf11c3f2a9baca97665240f4197a66e387be7bfea (diff)
parentdd899d20964342f22f4a82912d5722a5c9f5e663 (diff)
downloadtext.love-03f3034930f7ac37a23cf6353f0a662e8967f200.tar.gz
Merge lines.love
-rw-r--r--edit.lua8
-rw-r--r--text.lua18
2 files changed, 12 insertions, 14 deletions
diff --git a/edit.lua b/edit.lua
index 2b23769..f2a1fa1 100644
--- a/edit.lua
+++ b/edit.lua
@@ -86,7 +86,8 @@ function edit.draw(State)
     print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos)
     assert(false)
   end
-  State.cursor_y = -1
+  State.cursor_x = nil
+  State.cursor_y = nil
   local y = State.top
 --?   print('== draw')
   for line_index = State.screen_top1.line,#State.lines do
@@ -103,9 +104,6 @@ function edit.draw(State)
     y = y + State.line_height
 --?     print('=> y', y)
   end
-  if State.cursor_y == -1 then
-    State.cursor_y = App.screen.height
-  end
 --?   print('screen bottom: '..tostring(State.screen_bottom1.pos)..' in '..tostring(State.lines[State.screen_bottom1.line].data))
   if State.search_term then
     Text.draw_search_bar(State)
@@ -301,7 +299,7 @@ function edit.keychord_pressed(State, chord, key)
         Text.insert_at_cursor(State, c)
       end
     end
-    if Text.cursor_past_screen_bottom(State) then
+    if Text.cursor_out_of_screen(State) then
       Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
     end
     schedule_save(State)
diff --git a/text.lua b/text.lua
index 27b0def..51c6d0d 100644
--- a/text.lua
+++ b/text.lua
@@ -155,7 +155,7 @@ function Text.textinput(State, t)
   local before = snapshot(State, State.cursor1.line)
 --?   print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
   Text.insert_at_cursor(State, t)
-  if State.cursor_y >= App.screen.height - State.line_height then
+  if State.cursor_y > App.screen.height - State.line_height then
     Text.populate_screen_line_starting_pos(State, State.cursor1.line)
     Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
 --?     print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
@@ -179,7 +179,7 @@ function Text.keychord_pressed(State, chord)
     local before = snapshot(State, before_line)
     Text.insert_return(State)
     State.selection1 = {}
-    if (State.cursor_y + State.line_height) > App.screen.height then
+    if State.cursor_y > App.screen.height - State.line_height then
       Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
     end
     schedule_save(State)
@@ -188,7 +188,7 @@ function Text.keychord_pressed(State, chord)
     local before = snapshot(State, State.cursor1.line)
 --?     print(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
     Text.insert_at_cursor(State, '\t')
-    if State.cursor_y >= App.screen.height - State.line_height then
+    if State.cursor_y > App.screen.height - State.line_height then
       Text.populate_screen_line_starting_pos(State, State.cursor1.line)
       Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
 --?       print('=>', State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos, State.screen_bottom1.line, State.screen_bottom1.pos)
@@ -506,7 +506,7 @@ function Text.end_of_line(State)
   State.cursor1.pos = utf8.len(State.lines[State.cursor1.line].data) + 1
   local botpos = Text.pos_at_start_of_cursor_screen_line(State)
   local botline1 = {line=State.cursor1.line, pos=botpos}
-  if Text.cursor_past_screen_bottom(State) then
+  if Text.cursor_out_of_screen(State) then
     Text.snap_cursor_to_bottom_of_screen(State)
   end
 end
@@ -555,7 +555,7 @@ function Text.word_right(State)
       break
     end
   end
-  if Text.cursor_past_screen_bottom(State) then
+  if Text.cursor_out_of_screen(State) then
     Text.snap_cursor_to_bottom_of_screen(State)
   end
 end
@@ -585,7 +585,7 @@ end
 
 function Text.right(State)
   Text.right_without_scroll(State)
-  if Text.cursor_past_screen_bottom(State) then
+  if Text.cursor_out_of_screen(State) then
     Text.snap_cursor_to_bottom_of_screen(State)
   end
 end
@@ -896,7 +896,7 @@ function Text.tweak_screen_top_and_cursor(State)
     State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
   elseif State.cursor1.line >= State.screen_bottom1.line then
 --?     print('too low')
-    if Text.cursor_past_screen_bottom(State) then
+    if Text.cursor_out_of_screen(State) then
 --?       print('tweak')
       State.cursor1 = {
           line=State.screen_bottom1.line,
@@ -907,9 +907,9 @@ function Text.tweak_screen_top_and_cursor(State)
 end
 
 -- slightly expensive since it redraws the screen
-function Text.cursor_past_screen_bottom(State)
+function Text.cursor_out_of_screen(State)
   App.draw()
-  return State.cursor_y >= App.screen.height - State.line_height
+  return State.cursor_y == nil
   -- this approach is cheaper and almost works, except on the final screen
   -- where file ends above bottom of screen
 --?   local botpos = Text.pos_at_start_of_cursor_screen_line(State)