about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--edit.lua4
-rw-r--r--select.lua2
-rw-r--r--text.lua34
3 files changed, 20 insertions, 20 deletions
diff --git a/edit.lua b/edit.lua
index a0ac010..fc0f6ec 100644
--- a/edit.lua
+++ b/edit.lua
@@ -391,8 +391,8 @@ function edit.keychord_pressed(State, chord, key)
         Text.insert_at_cursor(State, c)
       end
     end
-    if Text.cursor_past_screen_bottom() then
-      Text.snap_cursor_to_bottom_of_screen(State.margin_left, App.screen.height-State.margin_right)
+    if Text.cursor_past_screen_bottom(State) then
+      Text.snap_cursor_to_bottom_of_screen(State, State.margin_left, App.screen.height-State.margin_right)
     end
     schedule_save(State)
     record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
diff --git a/select.lua b/select.lua
index 1b74858..8c015f6 100644
--- a/select.lua
+++ b/select.lua
@@ -133,7 +133,7 @@ function Text.delete_selection_without_undo(State, left, right)
   State.cursor1.pos = minp
   if Text.lt1(State.cursor1, State.screen_top1) then
     State.screen_top1.line = State.cursor1.line
-    _,State.screen_top1.pos = Text.pos_at_start_of_cursor_screen_line(left, right)
+    _,State.screen_top1.pos = Text.pos_at_start_of_cursor_screen_line(State, left, right)
   end
   State.selection1 = {}
   -- delete everything between min (inclusive) and max (exclusive)
diff --git a/text.lua b/text.lua
index 314cca3..ca11cc5 100644
--- a/text.lua
+++ b/text.lua
@@ -403,7 +403,7 @@ end
 function Text.up(State, left, right)
   assert(State.lines[State.cursor1.line].mode == 'text')
 --?   print('up', State.cursor1.line, State.cursor1.pos, State.screen_top1.line, State.screen_top1.pos)
-  local screen_line_index,screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line(left, right)
+  local screen_line_index,screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line(State, left, right)
   if screen_line_starting_pos == 1 then
 --?     print('cursor is at first screen line of its line')
     -- line is done; skip to previous text line
@@ -480,7 +480,7 @@ function Text.down(State, left, right)
       scroll_down = true
     end
 --?     print('cursor is NOT at final screen line of its line')
-    local screen_line_index, screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line(left, right)
+    local screen_line_index, screen_line_starting_pos = Text.pos_at_start_of_cursor_screen_line(State, left, right)
     new_screen_line_starting_pos = State.lines[State.cursor1.line].screen_line_starting_pos[screen_line_index+1]
 --?     print('switching pos of screen line at cursor from '..tostring(screen_line_starting_pos)..' to '..tostring(new_screen_line_starting_pos))
     local new_screen_line_starting_byte_offset = Text.offset(State.lines[State.cursor1.line].data, new_screen_line_starting_pos)
@@ -505,9 +505,9 @@ end
 
 function Text.end_of_line(State, left, right)
   State.cursor1.pos = utf8.len(State.lines[State.cursor1.line].data) + 1
-  local _,botpos = Text.pos_at_start_of_cursor_screen_line(left, right)
+  local _,botpos = Text.pos_at_start_of_cursor_screen_line(State, left, right)
   local botline1 = {line=State.cursor1.line, pos=botpos}
-  if Text.cursor_past_screen_bottom() then
+  if Text.cursor_past_screen_bottom(State) then
     Text.snap_cursor_to_bottom_of_screen(left, right)
   end
 end
@@ -556,7 +556,7 @@ function Text.word_right(State, left, right)
       break
     end
   end
-  if Text.cursor_past_screen_bottom() then
+  if Text.cursor_past_screen_bottom(State) then
     Text.snap_cursor_to_bottom_of_screen(left, right)
   end
 end
@@ -594,7 +594,7 @@ end
 
 function Text.right(State, left, right)
   Text.right_without_scroll(State)
-  if Text.cursor_past_screen_bottom() then
+  if Text.cursor_past_screen_bottom(State) then
     Text.snap_cursor_to_bottom_of_screen(left, right)
   end
 end
@@ -616,11 +616,11 @@ function Text.right_without_scroll(State)
   end
 end
 
-function Text.pos_at_start_of_cursor_screen_line(left, right)
-  Text.populate_screen_line_starting_pos(Editor_state.lines[Editor_state.cursor1.line], left, right)
-  for i=#Editor_state.lines[Editor_state.cursor1.line].screen_line_starting_pos,1,-1 do
-    local spos = Editor_state.lines[Editor_state.cursor1.line].screen_line_starting_pos[i]
-    if spos <= Editor_state.cursor1.pos then
+function Text.pos_at_start_of_cursor_screen_line(State, left, right)
+  Text.populate_screen_line_starting_pos(State.lines[State.cursor1.line], left, right)
+  for i=#State.lines[State.cursor1.line].screen_line_starting_pos,1,-1 do
+    local spos = State.lines[State.cursor1.line].screen_line_starting_pos[i]
+    if spos <= State.cursor1.pos then
       return i,spos
     end
   end
@@ -973,7 +973,7 @@ function Text.tweak_screen_top_and_cursor(left, right)
     Editor_state.cursor1 = {line=Editor_state.screen_top1.line, pos=Editor_state.screen_top1.pos}
   elseif Editor_state.cursor1.line >= Editor_state.screen_bottom1.line then
 --?     print('too low')
-    if Text.cursor_past_screen_bottom() then
+    if Text.cursor_past_screen_bottom(Editor_state) then
 --?       print('tweak')
       local line = Editor_state.lines[Editor_state.screen_bottom1.line]
       Editor_state.cursor1 = {
@@ -985,14 +985,14 @@ function Text.tweak_screen_top_and_cursor(left, right)
 end
 
 -- slightly expensive since it redraws the screen
-function Text.cursor_past_screen_bottom()
+function Text.cursor_past_screen_bottom(State)
   App.draw()
-  return Editor_state.cursor_y >= App.screen.height - Editor_state.line_height
+  return State.cursor_y >= App.screen.height - State.line_height
   -- 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(left, right)
---?   local botline1 = {line=Editor_state.cursor1.line, pos=botpos}
---?   return Text.lt1(Editor_state.screen_bottom1, botline1)
+--?   local _,botpos = Text.pos_at_start_of_cursor_screen_line(State, left, right)
+--?   local botline1 = {line=State.cursor1.line, pos=botpos}
+--?   return Text.lt1(State.screen_bottom1, botline1)
 end
 
 function Text.redraw_all()