diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-06-20 11:25:00 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-06-20 11:31:14 -0700 |
commit | 3986e99fe0586e35a0c649114a07e6dd90f769fc (patch) | |
tree | 240a7e744e8566905d28dd93ad123f4e9db073d3 /main.lua | |
parent | 3be413602a59ed735a33712380cedbdb8f5603df (diff) | |
download | view.love-3986e99fe0586e35a0c649114a07e6dd90f769fc.tar.gz |
no, that's not right
Bugfix: we want selections to persist even when we lift up the shift key. This requires hoisting some code inside every case inside the whole keypress hierarchy, to ensure we never clear selections before textinput events can handle them. Current cross-cutting concerns we're explicitly scattering code for. - autosave - undo - selection management
Diffstat (limited to 'main.lua')
-rw-r--r-- | main.lua | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/main.lua b/main.lua index df68da5..d4fd32a 100644 --- a/main.lua +++ b/main.lua @@ -407,6 +407,9 @@ function App.textinput(t) Text.textinput(t) end schedule_save() + if not App.shift_down() then + Selection1 = {} + end end function App.keychord_pressed(chord) @@ -438,15 +441,19 @@ function App.keychord_pressed(chord) Search_term = '' Search_backup = {cursor={line=Cursor1.line, pos=Cursor1.pos}, screen_top={line=Screen_top1.line, pos=Screen_top1.pos}} assert(Search_text == nil) + Selection1 = {} elseif chord == 'C-=' then initialize_font_settings(Font_height+2) Text.redraw_all() + Selection1 = {} elseif chord == 'C--' then initialize_font_settings(Font_height-2) Text.redraw_all() + Selection1 = {} elseif chord == 'C-0' then initialize_font_settings(20) Text.redraw_all() + Selection1 = {} elseif chord == 'C-z' then for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll local event = undo_event() @@ -459,6 +466,7 @@ function App.keychord_pressed(chord) Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaks schedule_save() end + Selection1 = {} elseif chord == 'C-y' then for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll local event = redo_event() @@ -471,6 +479,7 @@ function App.keychord_pressed(chord) Text.redraw_all() -- if we're scrolling, reclaim all fragments to avoid memory leaks schedule_save() end + Selection1 = {} -- clipboard elseif chord == 'C-c' then for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll @@ -478,6 +487,7 @@ function App.keychord_pressed(chord) if s then App.setClipboardText(s) end + Selection1 = {} elseif chord == 'C-x' then for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll local s = Text.cut_selection() @@ -485,6 +495,7 @@ function App.keychord_pressed(chord) App.setClipboardText(s) end schedule_save() + Selection1 = {} elseif chord == 'C-v' then for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll -- We don't have a good sense of when to scroll, so we'll be conservative @@ -506,6 +517,7 @@ function App.keychord_pressed(chord) end schedule_save() record_undo_event({before=before, after=snapshot(before_line, Cursor1.line)}) + Selection1 = {} -- dispatch to drawing or text elseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then -- DON'T reset line.y here @@ -553,7 +565,4 @@ function App.keychord_pressed(chord) end function App.keyreleased(key, scancode) - if not App.shift_down() then - Selection1 = {} - end end |