From 8a588880b7e7e808dc73e9e6b7e5eb7a42c1e2cb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 1 Dec 2023 21:52:10 -0800 Subject: [PATCH] manually maintain mouse button press state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- edit.lua | 2 ++ select.lua | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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