From 6dfe954c02dccfc043178ec65eb4706cbbde0ce8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 7 Jul 2022 07:39:01 -0700 Subject: [PATCH] yet another bugfix in selection management MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Leonard Schütz for the report! Failing scenario: click to move cursor hit backspace First backspace wasn't being doing anything earlier. --- main.lua | 7 +++++-- text_tests.lua | 19 +------------------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/main.lua b/main.lua index 5a42309..22585cf 100644 --- a/main.lua +++ b/main.lua @@ -341,8 +341,8 @@ function App.mousepressed(x,y, mouse_button) for line_index,line in ipairs(Lines) do if line.mode == 'text' then if Text.in_line(line_index,line, x,y) then - -- delicate dance between cursor, selection and old cursor - -- manual tests: + -- delicate dance between cursor, selection and old cursor/selection + -- scenarios: -- regular press+release: sets cursor, clears selection -- shift press+release: -- sets selection to old cursor if not set otherwise leaves it untouched @@ -396,6 +396,9 @@ function App.mousereleased(x,y, button) end end Old_cursor1, Old_selection1, Mousepress_shift = nil + if eq(Cursor1, Selection1) then + Selection1 = {} + end break end end diff --git a/text_tests.lua b/text_tests.lua index 025c76b..06af7e8 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -76,6 +76,7 @@ function test_click_with_mouse() App.run_after_mouse_click(Margin_left+8,Margin_top+5, 1) -- cursor moves check_eq(Cursor1.line, 1, 'F - test_click_with_mouse/cursor') + check_nil(Selection1.line, 'F - test_click_with_mouse/selection is empty to avoid perturbing future edits') end function test_click_with_mouse_on_empty_line() @@ -334,24 +335,6 @@ function test_cursor_movement_without_shift_resets_selection() check_eq(Lines[1].data, 'abc', 'F - test_cursor_movement_without_shift_resets_selection/data') end -function test_edit_after_click_resets_selection() - io.write('\ntest_edit_after_click_resets_selection') - -- display a line of text - App.screen.init{width=75, height=80} - Lines = load_array{'abc'} - Margin_right = 0; Margin_width = Margin_left - Cursor1 = {line=1, pos=1} - Screen_top1 = {line=1, pos=1} - Screen_bottom1 = {} - App.draw() - -- click past the end of it and hit enter - App.run_after_mouse_click(Margin_left+40,Margin_top+5, 1) - check(Selection1.line, 'F - test_edit_after_click_resets_selection/baseline') - App.run_after_keychord('return') - -- selection is reset since shift key is not pressed - check_nil(Selection1.line, 'F - test_edit_after_click_resets_selection') -end - function test_edit_deletes_selection() io.write('\ntest_edit_deletes_selection') -- display a line of text with some part selected -- 2.45.2