bugfix: typing should delete highlighted text
The test harness now also mimics real usage more precisely.
This commit is contained in:
parent
9aa7577446
commit
3be413602a
9
app.lua
9
app.lua
|
@ -232,14 +232,19 @@ function App.mouse_y()
|
||||||
return App.fake_mouse_state.y
|
return App.fake_mouse_state.y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- all textinput events are also keypresses
|
||||||
function App.run_after_textinput(t)
|
function App.run_after_textinput(t)
|
||||||
|
App.keypressed(t)
|
||||||
App.textinput(t)
|
App.textinput(t)
|
||||||
|
App.keyreleased(t)
|
||||||
App.screen.contents = {}
|
App.screen.contents = {}
|
||||||
App.draw()
|
App.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function App.run_after_keychord(key)
|
-- not all keys are textinput
|
||||||
App.keychord_pressed(key)
|
function App.run_after_keychord(chord)
|
||||||
|
App.keychord_pressed(chord)
|
||||||
|
App.keyreleased(chord)
|
||||||
App.screen.contents = {}
|
App.screen.contents = {}
|
||||||
App.draw()
|
App.draw()
|
||||||
end
|
end
|
||||||
|
|
12
main.lua
12
main.lua
|
@ -407,9 +407,6 @@ function App.textinput(t)
|
||||||
Text.textinput(t)
|
Text.textinput(t)
|
||||||
end
|
end
|
||||||
schedule_save()
|
schedule_save()
|
||||||
if not App.shift_down() then
|
|
||||||
Selection1 = {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function App.keychord_pressed(chord)
|
function App.keychord_pressed(chord)
|
||||||
|
@ -540,22 +537,23 @@ function App.keychord_pressed(chord)
|
||||||
local p = drawing.points[drawing.pending.target_point]
|
local p = drawing.points[drawing.pending.target_point]
|
||||||
if chord == 'escape' then
|
if chord == 'escape' then
|
||||||
p.name = nil
|
p.name = nil
|
||||||
|
record_undo_event({before=before, after=snapshot(Lines.current_drawing_index)})
|
||||||
elseif chord == 'backspace' then
|
elseif chord == 'backspace' then
|
||||||
local len = utf8.len(p.name)
|
local len = utf8.len(p.name)
|
||||||
local byte_offset = Text.offset(p.name, len-1)
|
local byte_offset = Text.offset(p.name, len-1)
|
||||||
p.name = string.sub(p.name, 1, byte_offset)
|
p.name = string.sub(p.name, 1, byte_offset)
|
||||||
|
record_undo_event({before=before, after=snapshot(Lines.current_drawing_index)})
|
||||||
end
|
end
|
||||||
record_undo_event({before=before, after=snapshot(Lines.current_drawing_index)})
|
|
||||||
end
|
end
|
||||||
schedule_save()
|
schedule_save()
|
||||||
else
|
else
|
||||||
for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll
|
for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll
|
||||||
Text.keychord_pressed(chord)
|
Text.keychord_pressed(chord)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function App.keyreleased(key, scancode)
|
||||||
if not App.shift_down() then
|
if not App.shift_down() then
|
||||||
Selection1 = {}
|
Selection1 = {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function App.keyreleased(key, scancode)
|
|
||||||
end
|
|
||||||
|
|
|
@ -204,6 +204,23 @@ function test_edit_after_click_resets_selection()
|
||||||
check_nil(Selection1.line, 'F - test_edit_after_click_resets_selection')
|
check_nil(Selection1.line, 'F - test_edit_after_click_resets_selection')
|
||||||
end
|
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()
|
function test_edit_wrapping_text()
|
||||||
io.write('\ntest_edit_wrapping_text')
|
io.write('\ntest_edit_wrapping_text')
|
||||||
App.screen.init{width=50, height=60}
|
App.screen.init{width=50, height=60}
|
||||||
|
|
Loading…
Reference in New Issue