From 8a588880b7e7e808dc73e9e6b7e5eb7a42c1e2cb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 1 Dec 2023 21:52:10 -0800 Subject: 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 ++ 1 file changed, 2 insertions(+) (limited to 'edit.lua') 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) -- cgit 1.4.1-2-gfad0