about summary refs log tree commit diff stats
path: root/select.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-06-04 15:11:24 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-06-04 15:11:24 -0700
commitbf2c2555d662865b94256e6e854acc0715fda6d1 (patch)
tree5c444b3e2abe7c3b220e4c03c09ece70a9e04946 /select.lua
parent074f4d9b0a51dc99df9183a45a9c2301f575b35b (diff)
parent637e28f300def4172459dd1d6fdf6efd53200ea8 (diff)
downloadview.love-bf2c2555d662865b94256e6e854acc0715fda6d1.tar.gz
Merge lines.love
Diffstat (limited to 'select.lua')
-rw-r--r--select.lua20
1 files changed, 4 insertions, 16 deletions
diff --git a/select.lua b/select.lua
index 0050895..a24b828 100644
--- a/select.lua
+++ b/select.lua
@@ -29,7 +29,6 @@ function Text.clip_selection(State, line_index, apos, bpos)
   -- compare bounds more carefully (start inclusive, end exclusive)
   local a_ge = Text.le1({line=minl, pos=minp}, {line=line_index, pos=apos})
   local b_lt = Text.lt1({line=line_index, pos=bpos}, {line=maxl, pos=maxp})
---?   print(minl,line_index,maxl, '--', minp,apos,bpos,maxp, '--', a_ge,b_lt)
   if a_ge and b_lt then
     -- fully contained
     return apos,bpos
@@ -60,7 +59,6 @@ function Text.draw_highlight(State, line, x,y, pos, lo,hi)
       local before = line.data:sub(pos_offset, lo_offset-1)
       lo_px = App.width(before)
     end
---?     print(lo,pos,hi, '--', lo_offset,pos_offset,hi_offset, '--', lo_px)
     local s = line.data:sub(lo_offset, hi_offset-1)
     App.color(Highlight_color)
     love.graphics.rectangle('fill', x+lo_px,y, App.width(s),State.line_height)
@@ -69,27 +67,17 @@ function Text.draw_highlight(State, line, x,y, pos, lo,hi)
   end
 end
 
--- inefficient for some reason, so don't do it on every frame
 function Text.mouse_pos(State)
-  local time = love.timer.getTime()
-  if State.recent_mouse.time and State.recent_mouse.time > time-0.1 then
-    return State.recent_mouse.line, State.recent_mouse.pos
+  local x,y = App.mouse_x(), App.mouse_y()
+  if y < State.line_cache[State.screen_top1.line].starty then
+    return State.screen_top1.line, State.screen_top1.pos
   end
-  State.recent_mouse.time = time
-  local line,pos = Text.to_pos(State, App.mouse_x(), App.mouse_y())
-  if line then
-    State.recent_mouse.line = line
-    State.recent_mouse.pos = pos
-  end
-  return State.recent_mouse.line, State.recent_mouse.pos
-end
-
-function Text.to_pos(State, x,y)
   for line_index,line in ipairs(State.lines) do
     if Text.in_line(State, line_index, x,y) then
       return line_index, Text.to_pos_on_line(State, line_index, x,y)
     end
   end
+  return State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1)
 end
 
 function Text.cut_selection(State)