To reproduce:
  click to position cursor at end of a line
  hit enter
  press any key

before:
  newline got erased and key got added to previous line

now:
  newline is preserved

The new test checks a generalization of this.
This commit is contained in:
Kartik K. Agaram 2022-06-19 09:21:32 -07:00
parent 703ed905c1
commit 3ffc2ed8f3
3 changed files with 27 additions and 1 deletions

View File

@ -347,6 +347,7 @@ function App.mousepressed(x,y, mouse_button)
Old_selection1 = Selection1
Mousepress_shift = App.shift_down()
Selection1 = {line=line_index, pos=Text.to_pos_on_line(line, x, y)}
--? print('selection')
end
elseif line.mode == 'drawing' then
if Drawing.in_drawing(line, x, y) then
@ -372,6 +373,7 @@ function App.mousereleased(x,y, button)
for line_index,line in ipairs(Lines) do
if line.mode == 'text' then
if Text.in_line(line_index,line, x,y) then
--? print('reset selection')
Cursor1 = {line=line_index, pos=Text.to_pos_on_line(line, x, y)}
--? print(Cursor1.line, Cursor1.pos)
if Mousepress_shift then
@ -405,6 +407,9 @@ function App.textinput(t)
Text.textinput(t)
end
schedule_save()
if not App.shift_down() then
Selection1 = {}
end
end
function App.keychord_pressed(chord)
@ -547,6 +552,9 @@ function App.keychord_pressed(chord)
for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll
Text.keychord_pressed(chord)
end
if not App.shift_down() then
Selection1 = {}
end
end
function App.keyreleased(key, scancode)

View File

@ -164,7 +164,7 @@ end
-- Don't handle any keys here that would trigger love.textinput above.
function Text.keychord_pressed(chord)
--? print('chord')
--? print('chord', chord, Selection1.line, Selection1.pos)
--== shortcuts that mutate text
if chord == 'return' then
local before_line = Cursor1.line

View File

@ -186,6 +186,24 @@ function test_click_on_wrapping_line_containing_non_ascii()
check_eq(Cursor1.pos, 15, 'F - test_click_on_wrapping_line_containing_non_ascii/cursor') -- one more than the number of UTF-8 code-points
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=80, height=80}
Lines = load_array{'abc'}
Line_width = 75
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_wrapping_text()
io.write('\ntest_edit_wrapping_text')
App.screen.init{width=50, height=60}