one bug I've repeatedly run into while testing with Moby Dick

[?]
May 24, 2022, 12:39 AM
R53OF3ONKT5VL5BGK63YSN6GXIIAVNYDG4UMHITK72WXFWPJ25MQC

Dependencies

  • [2] A2NV3WVO scrolling with up arrow
  • [3] XOAHJ6M3 similar tests for cursor up
  • [4] PYGMASTV disable some debug prints
  • [5] IMEJA43L snapshot
  • [6] C42QQZSF another piece of support for line wrapping in cursor up
  • [7] 2RXZ3PGO beginning of a new approach to scroll+wrap
  • [8] SVJZZDC3 snapshot - no, that's all wrong
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] YTSPVDZH first successful pagedown test, first bug found by test
  • [*] PFT5Y2ZY move
  • [*] MGT5FTJ3 first stab at supporting wrapping in cursor up
  • [*] 3CSIZJ33 clearer comments
  • [*] 3QNOKBFM beginnings of a test harness
  • [*] AVTNUQYR basic test-enabled framework

Change contents

  • replacement in text.lua at line 359
    [3.5311][2.486:552]()
    -- display lines starting from the second screen line of line 3
    [3.5311]
    [2.552]
    -- display lines starting from second screen line of a line
  • replacement in text.lua at line 374
    [2.906][3.6056:6122](),[3.6056][3.6056:6122]()
    -- after hitting the up arrow the screen scrolls up by one line
    [2.906]
    [3.6122]
    -- after hitting the up arrow the screen scrolls up to first screen line
  • edit in text.lua at line 388
    [11.2153]
    [12.1]
    function test_up_arrow_scrolls_up_to_final_screen_line()
    print('test_up_arrow_scrolls_up_to_final_screen_line')
    -- display lines starting just after a long 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_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:1')
    y = y + line_height
    App.screen.check(y, 'jkl', 'F - test_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:2')
    y = y + line_height
    App.screen.check(y, 'mno', 'F - test_up_arrow_scrolls_up_to_final_screen_line/baseline/screen:3')
    -- after hitting the up arrow the screen scrolls up to final screen line of previous line
    App.run_after_keychord('up')
    y = screen_top_margin
    App.screen.check(y, 'def', 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen:1')
    y = y + line_height
    App.screen.check(y, 'ghi', 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen:2')
    y = y + line_height
    App.screen.check(y, 'jkl', 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen:3')
    check_eq(Screen_top1.line, 1, 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen_top')
    check_eq(Screen_top1.pos, 5, 'F - test_up_arrow_scrolls_up_to_final_screen_line/screen_top')
    check_eq(Cursor1.line, 1, 'F - test_up_arrow_scrolls_up_to_final_screen_line/cursor')
    check_eq(Cursor1.pos, 5, 'F - test_up_arrow_scrolls_up_to_final_screen_line/cursor')
    end
  • edit in text.lua at line 593
    [13.358]
    [3.3789]
    --? print('found previous text line')
  • edit in text.lua at line 595
    [3.3830]
    [3.3830]
    Text.populate_screen_line_starting_pos(Cursor1.line)
  • edit in text.lua at line 601
    [14.118]
    [3.3987]
    --? print('has multiple screen lines')
  • edit in text.lua at line 603
    [3.4075]
    [3.270]
    --? print(#screen_line_starting_pos)
  • replacement in text.lua at line 606
    [3.238][3.4076:4175]()
    if Screen_top1.line == Cursor1.line and Screen_top1.pos == screen_line_starting_pos then
    [3.238]
    [3.4175]
    if Screen_top1.line > Cursor1.line then
    Screen_top1.line = Cursor1.line
  • edit in text.lua at line 923
    [3.8448]
    [10.1438]
    function Text.populate_screen_line_starting_pos(line_index)
    -- duplicate some logic from Text.draw
    local line = Lines[line_index]
    if line.fragments == nil then
    Text.compute_fragments(line, Line_width)
    end
    local x = 25
    local pos = 1
    for _, f in ipairs(line.fragments) do
    local frag, frag_text = f.data, f.text
    --? print(x, frag)
    -- render fragment
    local frag_width = math.floor(App.width(frag_text)*Zoom)
    if x + frag_width > Line_width then
    x = 25
    if line.screen_line_starting_pos == nil then
    line.screen_line_starting_pos = {1, pos}
    else
    table.insert(line.screen_line_starting_pos, pos)
    end
    end
    x = x + frag_width
    local frag_len = utf8.len(frag)
    pos = pos + frag_len
    end
    end
  • edit in app.lua at line 190
    [16.7197]
    [16.7197]
    --? print('checking for "'..expected_contents..'" at y '..tostring(y))