bugfix: down arrow doesn't scroll up unnecessarily

[?]
May 24, 2022, 10:01 PM
V5MJRFOZRVVDCPOWTLXPHS2HZBZKOOCPPKFMRP6MWZN6N62QLFAAC

Dependencies

  • [2] MDXGMZU2 disable all debug prints
  • [3] 2POFQQLW keep cursor on screen when pressing 'down'
  • [4] 3OKKTUT4 up and down arrow now moving by screen line where possible
  • [5] PR4KIAZD first stab at equally hacky cursor down support
  • [6] TRNWIQN6 more precise height calculation when scrolling up as much as possible while keeping cursor on screen
  • [7] 2RXZ3PGO beginning of a new approach to scroll+wrap
  • [8] ESETRNLB bugfix: printing the first part of a line at the bottom made it seem non-wrapping
  • [9] PYGMASTV disable some debug prints
  • [10] SVJZZDC3 snapshot - no, that's all wrong
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] IMEJA43L snapshot
  • [*] XOAHJ6M3 similar tests for cursor up

Change contents

  • edit in text.lua at line 313
    [13.4789]
    [14.279]
    end
    function test_page_down_followed_by_down_arrow_does_not_scroll_screen_up()
    io.write('\ntest_page_down_followed_by_down_arrow_does_not_scroll_screen_up')
    App.screen.init{width=25+30, height=60}
    Lines = load_array{'abc', 'def', 'ghijkl', 'mno'}
    Line_width = App.screen.width
    Cursor1 = {line=3, pos=1}
    Screen_top1 = {line=1, pos=1}
    Screen_bottom1 = {}
    Zoom = 1
    local screen_top_margin = 15 -- pixels
    local line_height = math.floor(15*Zoom) -- pixels
    App.draw()
    local y = screen_top_margin
    App.screen.check(y, 'abc', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:1')
    y = y + line_height
    App.screen.check(y, 'def', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:2')
    y = y + line_height
    App.screen.check(y, 'ghijk', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:3')
    -- after hitting pagedown the screen scrolls down to start of a long line
    App.run_after_keychord('pagedown')
    check_eq(Screen_top1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/screen_top')
    check_eq(Cursor1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/cursor:line')
    check_eq(Cursor1.pos, 1, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline2/cursor:pos')
    -- after hitting down arrow the screen doesn't scroll down further, and certainly doesn't scroll up
    App.run_after_keychord('down')
    check_eq(Screen_top1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen_top')
    check_eq(Cursor1.line, 3, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:line')
    check_eq(Cursor1.pos, 6, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:pos')
    y = screen_top_margin
    App.screen.check(y, 'ghijk', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:1')
    y = y + line_height
    App.screen.check(y, 'l', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:2')
    y = y + line_height
    App.screen.check(y, 'mno', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:3')
  • edit in text.lua at line 835
    [3.983]
    [2.928]
    local scroll_up = false
    if Cursor1.line > Screen_bottom1.line or (Cursor1.line == Screen_bottom1.line and Cursor1.pos >= Screen_bottom1.pos) then
    scroll_up = true
    end
  • replacement in text.lua at line 846
    [3.61][3.6141:6179](),[3.982][3.6141:6179](),[2.1208][3.6141:6179](),[3.6141][3.6141:6179](),[3.6179][2.1209:1256](),[3.108][3.1620:1666](),[3.158][3.1620:1666](),[3.1026][3.1620:1666](),[2.1256][3.1620:1666](),[3.1511][3.1620:1666](),[3.1620][3.1620:1666](),[3.1666][2.1257:1329]()
    Screen_top1.line = Cursor1.line
    --? print('scroll up preserving cursor')
    Text.scroll_up_while_cursor_on_screen()
    --? print('screen top after:', Screen_top1.line, Screen_top1.pos)
    [2.1208]
    [3.1313]
    if scroll_up then
    Screen_top1.line = Cursor1.line
    --? print('scroll up preserving cursor')
    Text.scroll_up_while_cursor_on_screen()
    --? print('screen top after:', Screen_top1.line, Screen_top1.pos)
    end