no selection if State didn't receive mouse_press

This change needs to get backported to all the other forks. We want to
retain the ability to draw other UI elements in our apps, and that means
we can't always assume that a mouse press and mouse release will happen
together. Instead, each layer should manage its own state machine, and
only check for events from the immediately lower layer.

This idea generalizes commit c3cdbb52a.
This commit is contained in:
Kartik K. Agaram 2023-12-01 20:31:25 -08:00
parent c3cdbb52a9
commit 9b62cf0afc
2 changed files with 3 additions and 1 deletions

View File

@ -159,6 +159,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 y < State.top then
State.old_cursor1 = State.cursor1
@ -209,6 +210,7 @@ end
function edit.mouse_release(State, x,y, mouse_button)
if State.search_term then return end
State.mouse_down = nil
--? 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}

View File

@ -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