M main.lua => main.lua +5 -2
@@ 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
M text_tests.lua => text_tests.lua +1 -18
@@ 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