Merge upstream into main
This commit is contained in:
commit
4cfce50862
10
text.lua
10
text.lua
|
@ -18,7 +18,7 @@ function Text.draw(State, line_index, y, startpos)
|
|||
-- wrap long lines
|
||||
local x = State.left
|
||||
local pos = 1
|
||||
local screen_line_starting_pos = 1
|
||||
local screen_line_starting_pos = State.screen_top1.pos
|
||||
if line_cache.fragments == nil then
|
||||
Text.compute_fragments(State, line_index)
|
||||
end
|
||||
|
@ -209,8 +209,12 @@ function Text.keychord_pressed(State, chord)
|
|||
end
|
||||
State.cursor1.line = State.cursor1.line-1
|
||||
end
|
||||
if Text.lt1(State.cursor1, State.screen_top1) then
|
||||
local top2 = Text.to2(State, State.screen_top1, State.left, State.right)
|
||||
if State.screen_top1.line > #State.lines then
|
||||
Text.populate_screen_line_starting_pos(State, #State.lines)
|
||||
local line_cache = State.line_cache[#State.line_cache]
|
||||
State.screen_top1 = {line=#State.lines, pos=line_cache.screen_line_starting_pos[#line_cache.screen_line_starting_pos]}
|
||||
elseif Text.lt1(State.cursor1, State.screen_top1) then
|
||||
local top2 = Text.to2(State, State.screen_top1)
|
||||
top2 = Text.previous_screen_line(State, top2, State.left, State.right)
|
||||
State.screen_top1 = Text.to1(State, top2)
|
||||
Text.redraw_all(State) -- if we're scrolling, reclaim all fragments to avoid memory leaks
|
||||
|
|
|
@ -42,6 +42,22 @@ function test_backspace_to_delete_drawing()
|
|||
check_eq(Editor_state.cursor1.line, 1, 'F - test_backspace_to_delete_drawing/cursor')
|
||||
end
|
||||
|
||||
function test_backspace_from_start_of_final_line()
|
||||
io.write('\ntest_backspace_from_start_of_final_line')
|
||||
-- display final line of text with cursor at start of it
|
||||
App.screen.init{width=120, height=60}
|
||||
Editor_state = edit.initialize_test_state()
|
||||
Editor_state.lines = load_array{'abc', 'def'}
|
||||
Editor_state.screen_top1 = {line=2, pos=1}
|
||||
Editor_state.cursor1 = {line=2, pos=1}
|
||||
Text.redraw_all(Editor_state)
|
||||
-- backspace scrolls up
|
||||
edit.run_after_keychord(Editor_state, 'backspace')
|
||||
check_eq(#Editor_state.lines, 1, 'F - test_backspace_from_start_of_final_line/#lines')
|
||||
check_eq(Editor_state.cursor1.line, 1, 'F - test_backspace_from_start_of_final_line/cursor')
|
||||
check_eq(Editor_state.screen_top1.line, 1, 'F - test_backspace_from_start_of_final_line/screen_top')
|
||||
end
|
||||
|
||||
function test_insert_first_character()
|
||||
io.write('\ntest_insert_first_character')
|
||||
App.screen.init{width=120, height=60}
|
||||
|
@ -1068,6 +1084,23 @@ function test_pagedown_can_start_from_middle_of_long_wrapping_line()
|
|||
App.screen.check(y, 'mno ', 'F - test_pagedown_can_start_from_middle_of_long_wrapping_line/screen:3')
|
||||
end
|
||||
|
||||
function test_pagedown_never_moves_up()
|
||||
io.write('\ntest_pagedown_never_moves_up')
|
||||
-- draw the final screen line of a wrapping line
|
||||
App.screen.init{width=Editor_state.left+30, height=60}
|
||||
Editor_state = edit.initialize_test_state()
|
||||
Editor_state.lines = load_array{'abc def ghi'}
|
||||
Text.redraw_all(Editor_state)
|
||||
Editor_state.cursor1 = {line=1, pos=9}
|
||||
Editor_state.screen_top1 = {line=1, pos=9}
|
||||
Editor_state.screen_bottom1 = {}
|
||||
edit.draw(Editor_state)
|
||||
-- pagedown makes no change
|
||||
edit.run_after_keychord(Editor_state, 'pagedown')
|
||||
check_eq(Editor_state.screen_top1.line, 1, 'F - test_pagedown_never_moves_up/screen_top:line')
|
||||
check_eq(Editor_state.screen_top1.pos, 9, 'F - test_pagedown_never_moves_up/screen_top:pos')
|
||||
end
|
||||
|
||||
function test_down_arrow_moves_cursor()
|
||||
io.write('\ntest_down_arrow_moves_cursor')
|
||||
App.screen.init{width=120, height=60}
|
||||
|
|
Loading…
Reference in New Issue
Block a user