bugfix: typing a capital letter deletes selection

This commit is contained in:
Kartik K. Agaram 2022-06-26 17:07:27 -07:00
parent 44fb3ecd55
commit 83ba9e61d1
3 changed files with 29 additions and 3 deletions

View File

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

View File

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

View File

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