bugfix: typing should delete highlighted text

The test harness now also mimics real usage more precisely.
This commit is contained in:
Kartik K. Agaram 2022-06-20 10:48:35 -07:00
parent 9aa7577446
commit 3be413602a
3 changed files with 29 additions and 9 deletions

View File

@ -232,14 +232,19 @@ function App.mouse_y()
return App.fake_mouse_state.y
end
-- all textinput events are also keypresses
function App.run_after_textinput(t)
App.keypressed(t)
App.textinput(t)
App.keyreleased(t)
App.screen.contents = {}
App.draw()
end
function App.run_after_keychord(key)
App.keychord_pressed(key)
-- not all keys are textinput
function App.run_after_keychord(chord)
App.keychord_pressed(chord)
App.keyreleased(chord)
App.screen.contents = {}
App.draw()
end

View File

@ -407,9 +407,6 @@ function App.textinput(t)
Text.textinput(t)
end
schedule_save()
if not App.shift_down() then
Selection1 = {}
end
end
function App.keychord_pressed(chord)
@ -540,22 +537,23 @@ function App.keychord_pressed(chord)
local p = drawing.points[drawing.pending.target_point]
if chord == 'escape' then
p.name = nil
record_undo_event({before=before, after=snapshot(Lines.current_drawing_index)})
elseif chord == 'backspace' then
local len = utf8.len(p.name)
local byte_offset = Text.offset(p.name, len-1)
p.name = string.sub(p.name, 1, byte_offset)
record_undo_event({before=before, after=snapshot(Lines.current_drawing_index)})
end
record_undo_event({before=before, after=snapshot(Lines.current_drawing_index)})
end
schedule_save()
else
for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll
Text.keychord_pressed(chord)
end
end
function App.keyreleased(key, scancode)
if not App.shift_down() then
Selection1 = {}
end
end
function App.keyreleased(key, scancode)
end

View File

@ -204,6 +204,23 @@ function test_edit_after_click_resets_selection()
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
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 a key
App.run_after_textinput('x')
-- selected text is deleted and replaced with the key
check_eq(Lines[1].data, 'xbc', 'F - test_edit_deletes_selection')
end
function test_edit_wrapping_text()
io.write('\ntest_edit_wrapping_text')
App.screen.init{width=50, height=60}