diff options
-rw-r--r-- | keychord.lua | 2 | ||||
-rw-r--r-- | main.lua | 8 | ||||
-rw-r--r-- | text_tests.lua | 22 |
3 files changed, 29 insertions, 3 deletions
diff --git a/keychord.lua b/keychord.lua index cc01241..ba0a47c 100644 --- a/keychord.lua +++ b/keychord.lua @@ -8,7 +8,7 @@ function App.keypressed(key, scancode, isrepeat) return end -- include the modifier(s) when the non-modifer is pressed - App.keychord_pressed(App.combine_modifiers(key)) + App.keychord_pressed(App.combine_modifiers(key), key) end function App.combine_modifiers(key) diff --git a/main.lua b/main.lua index 4eb3d5a..71c7e4d 100644 --- a/main.lua +++ b/main.lua @@ -413,8 +413,12 @@ function App.textinput(t) schedule_save() 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' and not App.is_cursor_movement(chord) then +function App.keychord_pressed(chord, key) + if Selection1.line and + -- printable character created using shift key => delete selection + -- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys) + (not App.shift_down() or utf8.len(key) == 1) 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 3c4349a..698c186 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -261,6 +261,28 @@ function test_edit_deletes_selection() check_eq(Lines[1].data, 'xbc', 'F - test_edit_deletes_selection') end +function test_edit_with_shift_key_deletes_selection() + io.write('\ntest_edit_with_shift_key_deletes_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() + -- mimic precise keypresses for a capital letter + App.fake_key_press('lshift') + App.keypressed('d') + App.textinput('D') + App.keyreleased('d') + App.fake_key_release('lshift') + -- selected text is deleted and replaced with the key + check_nil(Selection1.line, 'F - test_edit_with_shift_key_deletes_selection') + check_eq(Lines[1].data, 'Dbc', 'F - test_edit_with_shift_key_deletes_selection/data') +end + function test_copy_does_not_reset_selection() io.write('\ntest_copy_does_not_reset_selection') -- display a line of text with a selection |