bugfix: couple of margin-relative computations

[?]
Jul 18, 2022, 5:15 AM
EKKFWP4D2MNOHU265UCJU37KIFQV424CRLVASQMHDYUYY5T67D3QC

Dependencies

  • [2] ILOA5BYF separate data structure for each line's cache data
  • [3] IWYLK45K clicking to the right of a line within line width
  • [4] WOXIYUTL bugfix: manage screen_top and cursor when resizing
  • [5] QCPXQ2E3 add state arg to a few functions
  • [6] FKNXK2OA switch to line index in a function
  • [7] MXA3RZYK deduce left/right from state where possible
  • [8] 4VKEE43Z bugfix
  • [9] UHB4GARJ left/right margin -> left/right coordinates
  • [10] WZFMGVDT switch to line index in a function
  • [11] J6WEC2D6 .
  • [12] BOFNXP5G clicking now moves the cursor even on long, wrapped lines
  • [13] 5L7K4GBD clicking to the right of a wrapped line
  • [14] LAW2O3NW extract variable Margin_left
  • [15] LF7BWEG4 group all editor globals
  • [16] LNUHQOGH start passing in Editor_state explicitly
  • [17] DRFE3B3Z mouse buttons are integers, not strings
  • [18] Y2ZIPXEM new test
  • [19] 7NQCCB34 .
  • [20] QLTJG7Q3 indent
  • [21] H3ECRBXF bugfix: clicking on empty lines
  • [22] APYPFFS3 call edit rather than App callbacks in tests
  • [*] LXTTOB33 extract a couple of files
  • [*] BULPIBEG beginnings of a module for the text editor

Change contents

  • replacement in text_tests.lua at line 268
    [3.471][3.7487:7564]()
    check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse/cursor')
    [3.471]
    [3.7564]
    check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse/cursor:line')
    check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse/cursor:pos')
  • edit in text_tests.lua at line 273
    [3.7]
    [3.7]
    function test_click_with_mouse_takes_margins_into_account()
    io.write('\ntest_click_with_mouse_takes_margins_into_account')
    -- display two lines with cursor on one of them
    App.screen.init{width=100, height=80}
    Editor_state = edit.initialize_test_state()
    Editor_state.left = 50 -- occupy only right side of screen
    Editor_state.lines = load_array{'abc', 'def'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=2, pos=1}
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.screen_bottom1 = {}
    -- click on the other line
    edit.draw(Editor_state)
    edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1)
    -- cursor moves
    check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_takes_margins_into_account/cursor:line')
    check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse_takes_margins_into_account/cursor:pos')
    check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_takes_margins_into_account/selection is empty to avoid perturbing future edits')
    end
  • edit in text_tests.lua at line 362
    [24.1759]
    [24.1759]
    end
    function test_click_with_mouse_on_wrapping_line()
    io.write('\ntest_click_with_mouse_on_wrapping_line')
    -- display two lines with cursor on one of them
    App.screen.init{width=50, height=80}
    Editor_state = edit.initialize_test_state()
    Editor_state.lines = load_array{'abc def ghi jkl mno pqr stu'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=1, pos=20}
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.screen_bottom1 = {}
    -- click on the other line
    edit.draw(Editor_state)
    edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1)
    -- cursor moves
    check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_wrapping_line/cursor:line')
    check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse_on_wrapping_line/cursor:pos')
    check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_on_wrapping_line/selection is empty to avoid perturbing future edits')
  • edit in text_tests.lua at line 383
    [24.1764]
    [24.1764]
    function test_click_with_mouse_on_wrapping_line_takes_margins_into_account()
    io.write('\ntest_click_with_mouse_on_wrapping_line_takes_margins_into_account')
    -- display two lines with cursor on one of them
    App.screen.init{width=100, height=80}
    Editor_state = edit.initialize_test_state()
    Editor_state.left = 50 -- occupy only right side of screen
    Editor_state.lines = load_array{'abc def ghi jkl mno pqr stu'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=1, pos=20}
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.screen_bottom1 = {}
    -- click on the other line
    edit.draw(Editor_state)
    edit.run_after_mouse_click(Editor_state, Editor_state.left+8,Editor_state.top+5, 1)
    -- cursor moves
    check_eq(Editor_state.cursor1.line, 1, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/cursor:line')
    check_eq(Editor_state.cursor1.pos, 2, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/cursor:pos')
    check_nil(Editor_state.selection1.line, 'F - test_click_with_mouse_on_wrapping_line_takes_margins_into_account/selection is empty to avoid perturbing future edits')
    end
  • replacement in text.lua at line 731
    [3.352][2.6002:6143]()
    if screen_line_index < #line_cache.screen_line_starting_pos and mx > Text.screen_line_width(State, line_index, screen_line_index) then
    [3.352]
    [3.1479]
    if screen_line_index < #line_cache.screen_line_starting_pos and mx > State.left + Text.screen_line_width(State, line_index, screen_line_index) then
  • replacement in text.lua at line 981
    [3.5776][3.99:209]()
    pos=Text.to_pos_on_line(State, State.screen_bottom1.line, App.screen.width-5, App.screen.height-5),
    [3.5776]
    [3.139]
    pos=Text.to_pos_on_line(State, State.screen_bottom1.line, State.right-5, App.screen.height-5),