about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-07-17 09:05:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-07-17 09:14:10 -0700
commit48b7de4fde195abc0e41deec709d2ba1f52f6fbb (patch)
tree32414e8df351837ea51d9ae7a3d282cfa13ce07d
parentc0ea3696075fb6e8369bb67449153e834d684101 (diff)
downloadview.love-48b7de4fde195abc0e41deec709d2ba1f52f6fbb.tar.gz
switch to line index in a function
  - Text.in_line
-rw-r--r--edit.lua4
-rw-r--r--select.lua2
-rw-r--r--text.lua3
3 files changed, 5 insertions, 4 deletions
diff --git a/edit.lua b/edit.lua
index f1c032f..2de3cb2 100644
--- a/edit.lua
+++ b/edit.lua
@@ -200,7 +200,7 @@ function edit.mouse_pressed(State, x,y, mouse_button)
 
   for line_index,line in ipairs(State.lines) do
     if line.mode == 'text' then
-      if Text.in_line(State, line, x,y) then
+      if Text.in_line(State, line_index, x,y) then
         -- delicate dance between cursor, selection and old cursor/selection
         -- scenarios:
         --  regular press+release: sets cursor, clears selection
@@ -245,7 +245,7 @@ function edit.mouse_released(State, x,y, mouse_button)
   else
     for line_index,line in ipairs(State.lines) do
       if line.mode == 'text' then
-        if Text.in_line(State, line, x,y) then
+        if Text.in_line(State, line_index, x,y) then
 --?           print('reset selection')
           State.cursor1 = {
               line=line_index,
diff --git a/select.lua b/select.lua
index 1240bb5..9e87081 100644
--- a/select.lua
+++ b/select.lua
@@ -93,7 +93,7 @@ end
 function Text.to_pos(State, x,y)
   for line_index,line in ipairs(State.lines) do
     if line.mode == 'text' then
-      if Text.in_line(State, line, x,y) then
+      if Text.in_line(State, line_index, x,y) then
         return line_index, Text.to_pos_on_line(State, line, x,y)
       end
     end
diff --git a/text.lua b/text.lua
index fec980b..d3998f9 100644
--- a/text.lua
+++ b/text.lua
@@ -693,7 +693,8 @@ function Text.snap_cursor_to_bottom_of_screen(State)
   Text.redraw_all(State)  -- if we're scrolling, reclaim all fragments to avoid memory leaks
 end
 
-function Text.in_line(State, line, x,y)
+function Text.in_line(State, line_index, x,y)
+  local line = State.lines[line_index]
   if line.starty == nil then return false end  -- outside current page
   if x < State.left then return false end
   if y < line.starty then return false end