bugfix: don't delete selection when moving cursor

This commit is contained in:
Kartik K. Agaram 2022-06-23 12:05:36 -07:00
parent da9d948615
commit 84875f3c43
3 changed files with 23 additions and 1 deletions

View File

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

View File

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

View File

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