a few tests for pageup, and a bugfix

[?]
May 24, 2022, 3:57 AM
4RUI5X52CSQODLT3WI4VBMXWZLACBYV5QANGDKRWS3VONZPVSEEQC

Dependencies

  • [2] R53OF3ON one bug I've repeatedly run into while testing with Moby Dick
  • [3] VCMS2CWT bugfix: escape key to hide online help
  • [4] IRV65LZP fold variables for screen dimensions into the app framework
  • [5] 252M2QMD forgot to move this special case out
  • [6] DLQMM265 scroll past first page
  • [7] MDXGMZU2 disable all debug prints
  • [8] XNFTJHC4 split keyboard handling between Text and Drawing
  • [9] 2RXZ3PGO beginning of a new approach to scroll+wrap
  • [10] DXT4QTAH a few more integer coordinates
  • [11] U7M4M2F7 bugfix: don't rely on Screen_bottom1 while scrolling
  • [12] 242L3OQX bugfix: ensure Cursor_line is always on a text line
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] PFT5Y2ZY move
  • [*] OTIBCAUJ love2d scaffold
  • [*] OIB2QPRC start remembering where the cursor is drawn in px
  • [*] V5TP27FP ctrl-+ and ctrl-- to adjust font size

Change contents

  • edit in text.lua at line 421
    [2.1842]
    [15.1]
    function test_pageup()
    io.write('\ntest_pageup')
    App.screen.init{width=120, height=45}
    Lines = load_array{'abc', 'def', 'ghi'}
    Line_width = App.screen.width
    Cursor1 = {line=2, pos=1}
    Screen_top1 = {line=2, pos=1}
    Screen_bottom1 = {}
    Zoom = 1
    local screen_top_margin = 15 -- pixels
    local line_height = math.floor(15*Zoom) -- pixels
    -- initially the last two lines are displayed
    App.draw()
    local y = screen_top_margin
    App.screen.check(y, 'def', 'F - test_pageup/baseline/screen:1')
    y = y + line_height
    App.screen.check(y, 'ghi', 'F - test_pageup/baseline/screen:2')
    -- after pageup the cursor goes to first line
    App.run_after_keychord('pageup')
    check_eq(Screen_top1.line, 1, 'F - test_pageup/screen_top')
    check_eq(Cursor1.line, 1, 'F - test_pageup/cursor')
    y = screen_top_margin
    App.screen.check(y, 'abc', 'F - test_pageup/screen:1')
    y = y + line_height
    App.screen.check(y, 'def', 'F - test_pageup/screen:2')
    end
    function test_pageup_scrolls_up_by_screen_line()
    io.write('\ntest_pageup_scrolls_up_by_screen_line')
    -- display the first three lines with the cursor on the bottom line
    App.screen.init{width=25+30, height=60}
    Lines = load_array{'abc def', 'ghi', 'jkl', 'mno'}
    Line_width = App.screen.width
    Cursor1 = {line=2, pos=1}
    Screen_top1 = {line=2, 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, 'ghi', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:1')
    y = y + line_height
    App.screen.check(y, 'jkl', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:2')
    y = y + line_height
    App.screen.check(y, 'mno', 'F - test_pageup_scrolls_up_by_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
    -- after hitting the page-up key the screen scrolls up to top
    App.run_after_keychord('pageup')
    check_eq(Screen_top1.line, 1, 'F - test_pageup_scrolls_up_by_screen_line/screen_top')
    check_eq(Cursor1.line, 1, 'F - test_pageup_scrolls_up_by_screen_line/cursor:line')
    check_eq(Cursor1.pos, 1, 'F - test_pageup_scrolls_up_by_screen_line/cursor:pos')
    y = screen_top_margin
    App.screen.check(y, 'abc ', 'F - test_pageup_scrolls_up_by_screen_line/screen:1')
    y = y + line_height
    App.screen.check(y, 'def', 'F - test_pageup_scrolls_up_by_screen_line/screen:2')
    y = y + line_height
    App.screen.check(y, 'ghi', 'F - test_pageup_scrolls_up_by_screen_line/screen:3')
    end
    function test_pageup_scrolls_up_from_middle_screen_line()
    io.write('\ntest_pageup_scrolls_up_from_middle_screen_line')
    -- display a few lines starting from the middle of a line (Cursor1.pos > 1)
    App.screen.init{width=25+30, height=60}
    Lines = load_array{'abc def', 'ghi jkl', 'mno'}
    Line_width = App.screen.width
    Cursor1 = {line=2, pos=5}
    Screen_top1 = {line=2, pos=5}
    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, 'jkl', 'F - test_pageup_scrolls_up_from_middle_screen_line/baseline/screen:2')
    y = y + line_height
    App.screen.check(y, 'mno', 'F - test_pageup_scrolls_up_from_middle_screen_line/baseline/screen:3') -- line wrapping includes trailing whitespace
    -- after hitting the page-up key the screen scrolls up to top
    App.run_after_keychord('pageup')
    check_eq(Screen_top1.line, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/screen_top')
    check_eq(Cursor1.line, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/cursor:line')
    check_eq(Cursor1.pos, 1, 'F - test_pageup_scrolls_up_from_middle_screen_line/cursor:pos')
    y = screen_top_margin
    App.screen.check(y, 'abc ', 'F - test_pageup_scrolls_up_from_middle_screen_line/screen:1')
    y = y + line_height
    App.screen.check(y, 'def', 'F - test_pageup_scrolls_up_from_middle_screen_line/screen:2')
    y = y + line_height
    App.screen.check(y, 'ghi ', 'F - test_pageup_scrolls_up_from_middle_screen_line/screen:3')
    end
  • edit in main.lua at line 71
    [3.204]
    [17.54]
    --? App.screen.width = 120
    --? App.screen.height = 200
    --? love.window.setMode(App.screen.width, App.screen.height)
  • edit in main.lua at line 82
    [3.255]
    [18.1]
    --? Line_width = 100
  • replacement in main.lua at line 245
    [3.1796][3.405:437](),[3.437][3.1824:1844](),[3.1824][3.1824:1844](),[3.1844][3.9628:9674](),[3.9674][3.274:308](),[3.1889][3.274:308](),[3.308][3.9675:9789]()
    local y = App.screen.height
    while y >= 0 do
    if Screen_top1.line == 1 then break end
    y = y - math.floor(15*Zoom)
    if Lines[Screen_top1.line].mode == 'drawing' then
    y = y - Drawing.pixels(Lines[Screen_top1.line].h)
    [3.1796]
    [3.2033]
    local top2 = Text.to2(Screen_top1)
    --? print(App.screen.height)
    local y = App.screen.height - math.floor(15*Zoom)
    while y >= 15 do
    --? print(y, top2.line)
    if Screen_top1.line == 1 and Screen_top1.pos == 1 then break end
    if Lines[Screen_top1.line].mode == 'text' then
    y = y - math.floor(15*Zoom)
    elseif Lines[Screen_top1.line].mode == 'drawing' then
    y = y - 20 - Drawing.pixels(Lines[Screen_top1.line].h)
  • replacement in main.lua at line 256
    [3.2043][3.9790:9836]()
    Screen_top1.line = Screen_top1.line - 1
    [3.2043]
    [3.2087]
    top2 = Text.previous_screen_line(top2)
  • replacement in main.lua at line 258
    [3.2095][3.9837:9904](),[3.2159][3.155:163](),[3.9904][3.155:163](),[3.155][3.155:163]()
    if Cursor1.line ~= Screen_top1.line then
    Cursor1.pos = 1
    end
    [3.2095]
    [3.9905]
    Screen_top1 = Text.to1(top2)
  • edit in main.lua at line 260
    [3.9941]
    [3.1099]
    Cursor1.pos = Screen_top1.pos
  • edit in main.lua at line 262
    [3.1180]
    [3.5015]
    --? print(Cursor1.line, Cursor1.pos, Screen_top1.line, Screen_top1.pos)