diff --git a/main.lua b/main.lua index c6829af..bb48ba3 100644 --- a/main.lua +++ b/main.lua @@ -166,6 +166,7 @@ function App.draw() Text.draw_cursor(25, y) end end + Screen_bottom1.pos = Screen_top1.pos y = y + Line_height elseif line.mode == 'drawing' then y = y+10 -- padding diff --git a/text.lua b/text.lua index 88ee18d..df491c7 100644 --- a/text.lua +++ b/text.lua @@ -156,9 +156,8 @@ function Text.insert_at_cursor(t) Lines[Cursor1.line].data = string.sub(Lines[Cursor1.line].data, 1, byte_offset-1)..t..string.sub(Lines[Cursor1.line].data, byte_offset) Lines[Cursor1.line].fragments = nil Lines[Cursor1.line].screen_line_starting_pos = nil - local scroll_down = Text.le1(Screen_bottom1, Cursor1) Cursor1.pos = Cursor1.pos+1 - if scroll_down then + if Cursor_y >= App.screen.height - Line_height then Text.populate_screen_line_starting_pos(Cursor1.line) Text.snap_cursor_to_bottom_of_screen() --? print('=>', Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos) diff --git a/text_tests.lua b/text_tests.lua index ae7e794..4a6203f 100644 --- a/text_tests.lua +++ b/text_tests.lua @@ -132,7 +132,7 @@ end function test_insert_from_clipboard() io.write('\ntest_insert_from_clipboard') - -- display a few lines with cursor on bottom line + -- display a few lines App.screen.init{width=25+30, height=60} Lines = load_array{'abc', 'def', 'ghi', 'jkl'} Line_width = App.screen.width @@ -146,7 +146,7 @@ function test_insert_from_clipboard() App.screen.check(y, 'def', 'F - test_insert_from_clipboard/baseline/screen:2') y = y + Line_height App.screen.check(y, 'ghi', 'F - test_insert_from_clipboard/baseline/screen:3') - -- after hitting the enter key the screen scrolls down + -- paste some text including a newline, check that new line is created App.clipboard = 'xy\nz' App.run_after_keychord('C-v') check_eq(Screen_top1.line, 1, 'F - test_insert_from_clipboard/screen_top') @@ -736,6 +736,25 @@ function test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom() App.screen.check(y, 'kl', 'F - test_enter_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen:2') end +function test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom() + io.write('\ntest_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom') + -- display just an empty bottom line on screen + App.screen.init{width=25+30, height=60} + Lines = load_array{'abc', ''} + Line_width = App.screen.width + Cursor1 = {line=2, pos=1} + Screen_top1 = {line=2, pos=1} + Screen_bottom1 = {} + App.draw() + -- after hitting the inserting_text key the screen does not scroll down + App.run_after_textinput('a') + check_eq(Screen_top1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen_top') + check_eq(Cursor1.line, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:line') + check_eq(Cursor1.pos, 2, 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/cursor:pos') + local y = Margin_top + App.screen.check(y, 'a', 'F - test_inserting_text_on_final_line_avoids_scrolling_down_when_not_at_bottom/screen:1') +end + function test_typing_on_bottom_line_scrolls_down() io.write('\ntest_typing_on_bottom_line_scrolls_down') -- display a few lines with cursor on bottom line