bugfix: scrolling in left/right movements

[?]
Jun 29, 2022, 1:48 AM
HTWAM4NZFOY463TNSKYIM2EWB7QNBGDRRTTGHF5N3Z4TGC7Q3SFAC

Dependencies

  • [2] NZKYPBSK check for scroll when just typing
  • [3] EBBFOW4X bugfix: clear selection in a couple more places
  • [4] MDXGMZU2 disable all debug prints
  • [5] XNFTJHC4 split keyboard handling between Text and Drawing
  • [6] ZPUQSPQP extract a few methods
  • [7] KECEMMMR extract couple of functions
  • [8] SVJZZDC3 snapshot - no, that's all wrong
  • [9] AVLAYODP much simpler
  • [10] DHI6IJCN selecting text and deleting selections
  • [11] X75QPYVW move Selection1 clearing past business logic
  • [12] CG3264MM move
  • [13] 4KOI3E6R remove some redundant checks
  • [*] LXTTOB33 extract a couple of files
  • [*] BULPIBEG beginnings of a module for the text editor

Change contents

  • edit in text_tests.lua at line 1153
    [2.1484]
    [2.1484]
    end
    function test_left_arrow_scrolls_up_in_wrapped_line()
    io.write('\ntest_left_arrow_scrolls_up_in_wrapped_line')
    -- display lines starting from second screen line of a line
    App.screen.init{width=Margin_left+30, height=60}
    Lines = load_array{'abc', 'def', 'ghi jkl', 'mno'}
    Line_width = App.screen.width
    Screen_top1 = {line=3, pos=5}
    Screen_bottom1 = {}
    -- cursor is at top of screen
    Cursor1 = {line=3, pos=5}
    App.draw()
    local y = Margin_top
    App.screen.check(y, 'jkl', 'F - test_left_arrow_scrolls_up_in_wrapped_line/baseline/screen:1')
    y = y + Line_height
    App.screen.check(y, 'mno', 'F - test_left_arrow_scrolls_up_in_wrapped_line/baseline/screen:2')
    -- after hitting the left arrow the screen scrolls up to first screen line
    App.run_after_keychord('left')
    y = Margin_top
    App.screen.check(y, 'ghi ', 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen:1')
    y = y + Line_height
    App.screen.check(y, 'jkl', 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen:2')
    y = y + Line_height
    App.screen.check(y, 'mno', 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen:3')
    check_eq(Screen_top1.line, 3, 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen_top')
    check_eq(Screen_top1.pos, 1, 'F - test_left_arrow_scrolls_up_in_wrapped_line/screen_top')
    check_eq(Cursor1.line, 3, 'F - test_left_arrow_scrolls_up_in_wrapped_line/cursor:line')
    check_eq(Cursor1.pos, 4, 'F - test_left_arrow_scrolls_up_in_wrapped_line/cursor:pos')
    end
    function test_right_arrow_scrolls_down_in_wrapped_line()
    io.write('\ntest_right_arrow_scrolls_down_in_wrapped_line')
    -- display the first three lines with the cursor on the bottom line
    App.screen.init{width=Margin_left+30, height=60}
    Lines = load_array{'abc', 'def', 'ghi jkl', 'mno'}
    Line_width = App.screen.width
    Screen_top1 = {line=1, pos=1}
    Screen_bottom1 = {}
    -- cursor is at bottom right of screen
    Cursor1 = {line=3, pos=5}
    App.draw()
    local y = Margin_top
    App.screen.check(y, 'abc', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:1')
    y = y + Line_height
    App.screen.check(y, 'def', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:2')
    y = y + Line_height
    App.screen.check(y, 'ghi ', 'F - test_right_arrow_scrolls_down_in_wrapped_line/baseline/screen:3') -- line wrapping includes trailing whitespace
    -- after hitting the right arrow the screen scrolls down by one line
    App.run_after_keychord('right')
    check_eq(Screen_top1.line, 2, 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen_top')
    check_eq(Cursor1.line, 3, 'F - test_right_arrow_scrolls_down_in_wrapped_line/cursor:line')
    check_eq(Cursor1.pos, 6, 'F - test_right_arrow_scrolls_down_in_wrapped_line/cursor:pos')
    y = Margin_top
    App.screen.check(y, 'def', 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen:1')
    y = y + Line_height
    App.screen.check(y, 'ghi ', 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen:2')
    y = y + Line_height
    App.screen.check(y, 'jkl', 'F - test_right_arrow_scrolls_down_in_wrapped_line/screen:3')
    end
    function test_home_scrolls_up_in_wrapped_line()
    io.write('\ntest_home_scrolls_up_in_wrapped_line')
    -- display lines starting from second screen line of a line
    App.screen.init{width=Margin_left+30, height=60}
    Lines = load_array{'abc', 'def', 'ghi jkl', 'mno'}
    Line_width = App.screen.width
    Screen_top1 = {line=3, pos=5}
    Screen_bottom1 = {}
    -- cursor is at top of screen
    Cursor1 = {line=3, pos=5}
    App.draw()
    local y = Margin_top
    App.screen.check(y, 'jkl', 'F - test_home_scrolls_up_in_wrapped_line/baseline/screen:1')
    y = y + Line_height
    App.screen.check(y, 'mno', 'F - test_home_scrolls_up_in_wrapped_line/baseline/screen:2')
    -- after hitting home the screen scrolls up to first screen line
    App.run_after_keychord('home')
    y = Margin_top
    App.screen.check(y, 'ghi ', 'F - test_home_scrolls_up_in_wrapped_line/screen:1')
    y = y + Line_height
    App.screen.check(y, 'jkl', 'F - test_home_scrolls_up_in_wrapped_line/screen:2')
    y = y + Line_height
    App.screen.check(y, 'mno', 'F - test_home_scrolls_up_in_wrapped_line/screen:3')
    check_eq(Screen_top1.line, 3, 'F - test_home_scrolls_up_in_wrapped_line/screen_top')
    check_eq(Screen_top1.pos, 1, 'F - test_home_scrolls_up_in_wrapped_line/screen_top')
    check_eq(Cursor1.line, 3, 'F - test_home_scrolls_up_in_wrapped_line/cursor:line')
    check_eq(Cursor1.pos, 1, 'F - test_home_scrolls_up_in_wrapped_line/cursor:pos')
  • edit in text_tests.lua at line 1243
    [2.1489]
    [15.31401]
    function test_end_scrolls_down_in_wrapped_line()
    io.write('\ntest_end_scrolls_down_in_wrapped_line')
    -- display the first three lines with the cursor on the bottom line
    App.screen.init{width=Margin_left+30, height=60}
    Lines = load_array{'abc', 'def', 'ghi jkl', 'mno'}
    Line_width = App.screen.width
    Screen_top1 = {line=1, pos=1}
    Screen_bottom1 = {}
    -- cursor is at bottom right of screen
    Cursor1 = {line=3, pos=5}
    App.draw()
    local y = Margin_top
    App.screen.check(y, 'abc', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:1')
    y = y + Line_height
    App.screen.check(y, 'def', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:2')
    y = y + Line_height
    App.screen.check(y, 'ghi ', 'F - test_end_scrolls_down_in_wrapped_line/baseline/screen:3') -- line wrapping includes trailing whitespace
    -- after hitting end the screen scrolls down by one line
    App.run_after_keychord('end')
    check_eq(Screen_top1.line, 2, 'F - test_end_scrolls_down_in_wrapped_line/screen_top')
    check_eq(Cursor1.line, 3, 'F - test_end_scrolls_down_in_wrapped_line/cursor:line')
    check_eq(Cursor1.pos, 8, 'F - test_end_scrolls_down_in_wrapped_line/cursor:pos')
    y = Margin_top
    App.screen.check(y, 'def', 'F - test_end_scrolls_down_in_wrapped_line/screen:1')
    y = y + Line_height
    App.screen.check(y, 'ghi ', 'F - test_end_scrolls_down_in_wrapped_line/screen:2')
    y = y + Line_height
    App.screen.check(y, 'jkl', 'F - test_end_scrolls_down_in_wrapped_line/screen:3')
    end
  • replacement in text.lua at line 297
    [4.107][4.1103:1123](),[4.9457][4.1103:1123](),[4.1103][4.1103:1123]()
    Cursor1.pos = 1
    [4.1103]
    [3.3]
    Text.start_of_line()
  • replacement in text.lua at line 300
    [4.115][4.1152:1209](),[4.128][4.1152:1209](),[4.9516][4.1152:1209](),[4.1152][4.1152:1209]()
    Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
    [4.115]
    [3.24]
    Text.end_of_line()
  • replacement in text.lua at line 306
    [4.9648][4.9648:9668]()
    Cursor1.pos = 1
    [4.9648]
    [4.9668]
    Text.start_of_line()
  • replacement in text.lua at line 311
    [4.9798][4.9798:9855]()
    Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
    [4.9798]
    [4.3956]
    Text.end_of_line()
  • edit in text.lua at line 500
    [4.4931]
    [4.4931]
    end
    function Text.start_of_line()
    Cursor1.pos = 1
    if Text.lt1(Cursor1, Screen_top1) then
    Screen_top1 = {line=Cursor1.line, pos=Cursor1.pos} -- copy
    end
    end
    function Text.end_of_line()
    Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
    local _,botpos = Text.pos_at_start_of_cursor_screen_line()
    local botline1 = {line=Cursor1.line, pos=botpos}
    if Text.lt1(Screen_bottom1, botline1) then
    Text.snap_cursor_to_bottom_of_screen()
    end
  • edit in text.lua at line 555
    [4.470][4.470:560]()
    end
    if Cursor1.line < Screen_top1.line then
    Screen_top1.line = Cursor1.line
  • edit in text.lua at line 556
    [4.568]
    [4.568]
    end
    if Text.lt1(Cursor1, Screen_top1) then
    local top2 = Text.to2(Screen_top1)
    top2 = Text.previous_screen_line(top2)
    Screen_top1 = Text.to1(top2)
  • edit in text.lua at line 577
    [4.1008][4.1008:1101]()
    end
    if Cursor1.line > Screen_bottom1.line then
    Screen_top1.line = Cursor1.line
  • edit in text.lua at line 579
    [4.1327]
    [4.1327]
    local _,botpos = Text.pos_at_start_of_cursor_screen_line()
    local botline1 = {line=Cursor1.line, pos=botpos}
    if Text.lt1(Screen_bottom1, botline1) then
    Text.snap_cursor_to_bottom_of_screen()
    end