about summary refs log tree commit diff stats
path: root/edit.lua
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-09-20 14:33:40 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-09-20 14:33:40 -0700
commita508c62497a6de4f7aeb67e0b4903741e0c15520 (patch)
tree93d4d53ff0bd258185206b7196d897ebc48550a5 /edit.lua
parent6d992144158bb6935ce77c68111726787f1361f1 (diff)
parent3aec915559514e8294f80447fcac9c4b34df9dc4 (diff)
downloadview.love-a508c62497a6de4f7aeb67e0b4903741e0c15520.tar.gz
Merge text.love
Diffstat (limited to 'edit.lua')
-rw-r--r--edit.lua39
1 files changed, 26 insertions, 13 deletions
diff --git a/edit.lua b/edit.lua
index a0145a0..262b63d 100644
--- a/edit.lua
+++ b/edit.lua
@@ -171,7 +171,7 @@ function edit.mouse_press(State, x,y, mouse_button)
     end
   end
 
-  -- still here? click is below all screen lines
+  -- still here? mouse press is below all screen lines
   State.old_cursor1 = State.cursor1
   State.old_selection1 = State.selection1
   State.mousepress_shift = App.shift_down()
@@ -184,6 +184,11 @@ end
 function edit.mouse_release(State, x,y, mouse_button)
   if State.search_term then return end
 --?   print_and_log(('edit.mouse_release(%d,%d): cursor at %d,%d'):format(x,y, State.cursor1.line, State.cursor1.pos))
+  if y < State.top then
+    State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}
+    edit.clean_up_mouse_press(State)
+    return
+  end
   for line_index,line in ipairs(State.lines) do
     if Text.in_line(State, line_index, x,y) then
 --?       print_and_log(('edit.mouse_release: in line %d'):format(line_index))
@@ -192,23 +197,31 @@ function edit.mouse_release(State, x,y, mouse_button)
           pos=Text.to_pos_on_line(State, line_index, x, y),
       }
 --?       print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos))
-      if State.mousepress_shift then
-        if State.old_selection1.line == nil then
-          State.selection1 = State.old_cursor1
-        else
-          State.selection1 = State.old_selection1
-        end
-      end
-      State.old_cursor1, State.old_selection1, State.mousepress_shift = nil
-      if eq(State.cursor1, State.selection1) then
-        State.selection1 = {}
-      end
-      break
+      edit.clean_up_mouse_press(State)
+      return
     end
   end
+
+  -- still here? mouse release is below all screen lines
+  State.cursor1.line, State.cursor1.pos = State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1)
+  edit.clean_up_mouse_press(State)
 --?   print_and_log(('edit.mouse_release: finally selection %s,%s cursor %d,%d'):format(tostring(State.selection1.line), tostring(State.selection1.pos), State.cursor1.line, State.cursor1.pos))
 end
 
+function edit.clean_up_mouse_press(State)
+  if State.mousepress_shift then
+    if State.old_selection1.line == nil then
+      State.selection1 = State.old_cursor1
+    else
+      State.selection1 = State.old_selection1
+    end
+  end
+  State.old_cursor1, State.old_selection1, State.mousepress_shift = nil
+  if eq(State.cursor1, State.selection1) then
+    State.selection1 = {}
+  end
+end
+
 function edit.mouse_wheel_move(State, dx,dy)
   if dy > 0 then
     State.cursor1 = {line=State.screen_top1.line, pos=State.screen_top1.pos}