diff options
-rw-r--r-- | keychord.lua | 4 | ||||
-rw-r--r-- | main.lua | 2 | ||||
-rw-r--r-- | text_tests.lua | 18 |
3 files changed, 23 insertions, 1 deletions
diff --git a/keychord.lua b/keychord.lua index 1eb42e9..cc01241 100644 --- a/keychord.lua +++ b/keychord.lua @@ -49,6 +49,10 @@ function App.cmd_down() return App.modifier_down('lgui') or App.modifier_down('rgui') end +function App.is_cursor_movement(key) + return array.find({'left', 'right', 'up', 'down', 'home', 'end', 'pageup', 'pagedown'}, key) +end + array = {} function array.find(arr, elem) diff --git a/main.lua b/main.lua index 60a0747..4eb3d5a 100644 --- a/main.lua +++ b/main.lua @@ -414,7 +414,7 @@ function App.textinput(t) end function App.keychord_pressed(chord) - if Selection1.line and not App.shift_down() and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and backspace ~= 'delete' then + if Selection1.line and not App.shift_down() and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and backspace ~= 'delete' and not App.is_cursor_movement(chord) then Text.delete_selection() end if Search_term then diff --git a/text_tests.lua b/text_tests.lua index dc5c0ff..64de74c 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -208,6 +208,24 @@ function test_select_text() check_eq(Cursor1.pos, 2, 'F - test_select_text/cursor:pos') end +function test_cursor_movement_without_shift_resets_selection() + io.write('\ntest_cursor_movement_without_shift_resets_selection') + -- display a line of text with some part selected + App.screen.init{width=80, height=80} + Lines = load_array{'abc'} + Line_width = 75 + Cursor1 = {line=1, pos=1} + Selection1 = {line=1, pos=2} + Screen_top1 = {line=1, pos=1} + Screen_bottom1 = {} + App.draw() + -- press an arrow key without shift + App.run_after_keychord('right') + -- no change to data, selection is reset + check_nil(Selection1.line, 'F - 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 |