about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-12-01 21:52:10 -0800
committerKartik K. Agaram <vc@akkartik.com>2023-12-01 21:56:35 -0800
commit8a588880b7e7e808dc73e9e6b7e5eb7a42c1e2cb (patch)
tree6f6876bd9b06e5ce38b7e91ca0b67287f5cda129
parent9ed7c576e6731334cd9e36285b98a2703c6564e1 (diff)
downloadlines.love-8a588880b7e7e808dc73e9e6b7e5eb7a42c1e2cb.tar.gz
manually maintain mouse button press state
Just checking mouse.isDown works if the editor is the entirety of the
app, as is true in this fork. However, we often want to introduce other
widgets. We'd like tapping on them to not cause the selection to flash:
  https://news.ycombinator.com/context?id=38404923&submission=38397715

The right architecture to enforce this is: have each layer of the UI
maintain its own state machine between mouse_press and mouse_release
events. And only check the state machine in the next level down rather
than lower layers or the bottommost layer of raw LÖVE.
-rw-r--r--edit.lua2
-rw-r--r--select.lua2
2 files changed, 3 insertions, 1 deletions
diff --git a/edit.lua b/edit.lua
index c8d5a03..0e552b7 100644
--- a/edit.lua
+++ b/edit.lua
@@ -233,6 +233,7 @@ end
 
 function edit.mouse_press(State, x,y, mouse_button)
   if State.search_term then return end
+  State.mouse_down = mouse_button
 --?   print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
   if mouse_press_consumed_by_any_button_handler(State, x,y, mouse_button) then
     -- press on a button and it returned 'true' to short-circuit
@@ -297,6 +298,7 @@ end
 function edit.mouse_release(State, x,y, mouse_button)
   if State.search_term then return end
 --?   print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
+  State.mouse_down = nil
   if State.lines.current_drawing then
     Drawing.mouse_release(State, x,y, mouse_button)
     schedule_save(State)
diff --git a/select.lua b/select.lua
index 9ede1da..5434988 100644
--- a/select.lua
+++ b/select.lua
@@ -11,7 +11,7 @@ function Text.clip_selection(State, line_index, apos, bpos)
   -- min,max = sorted(State.selection1,State.cursor1)
   local minl,minp = State.selection1.line,State.selection1.pos
   local maxl,maxp
-  if App.mouse_down(1) then
+  if State.mouse_down then
     maxl,maxp = Text.mouse_pos(State)
   else
     maxl,maxp = State.cursor1.line,State.cursor1.pos