keep text from overflowing right margin

[?]
Jul 19, 2022, 11:49 PM
GL4Q5WCVMOBEKW7SMBKRSL3DRG2NSTXRI7VQFK77OXAWLBDKWTNQC

Dependencies

  • [2] UHB4GARJ left/right margin -> left/right coordinates
  • [3] CUIV2LE5 some typos
  • [4] IWYLK45K clicking to the right of a line within line width
  • [5] MYC7XR5Q bugfix: lines that aren't drawn from the start
  • [6] 4VKEE43Z bugfix
  • [7] LF7BWEG4 group all editor globals
  • [8] APYPFFS3 call edit rather than App callbacks in tests
  • [9] 5Q6NIG66 bugfix
  • [10] VG75U7IM bugfix: typing should delete highlighted text
  • [11] M6TH7VSZ rip out notion of Line_width
  • [12] CNCYMM6A make test initializations a little more obvious
  • [13] ULKLJBN6 couple of renames
  • [14] LXTTOB33 extract a couple of files
  • [15] DGK5BPVI bugfix: UTF-8 in compute_fragments
  • [16] IMEJA43L snapshot
  • [17] HTWAM4NZ bugfix: scrolling in left/right movements
  • [18] NZKYPBSK check for scroll when just typing
  • [19] DRFE3B3Z mouse buttons are integers, not strings
  • [20] GJLOKCYK bugfix: clicking past end of screen line
  • [21] 2JLVAYHB start decoupling editor tests from App
  • [22] LNUHQOGH start passing in Editor_state explicitly
  • [23] LAW2O3NW extract variable Margin_left
  • [24] BULPIBEG beginnings of a module for the text editor

Change contents

  • replacement in text_tests.lua at line 341
    [3.8828][3.1010:1079](),[3.1010][3.1010:1079]()
    App.screen.check(y, 'def', 'F - test_draw_wrapping_text/screen:2')
    [3.8828]
    [3.8829]
    App.screen.check(y, 'de', 'F - test_draw_wrapping_text/screen:2')
  • replacement in text_tests.lua at line 343
    [3.8864][3.1101:1169](),[3.1101][3.1101:1169]()
    App.screen.check(y, 'gh', 'F - test_draw_wrapping_text/screen:3')
    [3.8864]
    [3.1169]
    App.screen.check(y, 'fgh', 'F - test_draw_wrapping_text/screen:3')
  • replacement in text_tests.lua at line 417
    [3.9576][3.2266:2350](),[3.2266][3.2266:2350]()
    App.screen.check(y, 'e fghi', 'F - test_draw_text_wrapping_within_word/screen:2')
    [3.9576]
    [3.9577]
    App.screen.check(y, 'e fgh', 'F - test_draw_text_wrapping_within_word/screen:2')
  • replacement in text_tests.lua at line 419
    [3.9612][3.2372:2452](),[3.2372][3.2372:2452]()
    App.screen.check(y, 'jk', 'F - test_draw_text_wrapping_within_word/screen:3')
    [3.9612]
    [3.2]
    App.screen.check(y, 'ijk', 'F - test_draw_text_wrapping_within_word/screen:3')
  • replacement in text_tests.lua at line 434
    [2.3259][3.440:531](),[3.9954][3.440:531](),[3.440][3.440:531]()
    App.screen.check(y, 'mada', 'F - test_draw_wrapping_text_containing_non_ascii/screen:1')
    [2.3259]
    [3.9955]
    App.screen.check(y, 'mad', 'F - test_draw_wrapping_text_containing_non_ascii/screen:1')
  • replacement in text_tests.lua at line 436
    [3.9990][3.553:646](),[3.553][3.553:646]()
    App.screen.check(y, 'm I’', 'F - test_draw_wrapping_text_containing_non_ascii/screen:2')
    [3.9990]
    [3.9991]
    App.screen.check(y, 'am ', 'F - test_draw_wrapping_text_containing_non_ascii/screen:2')
  • replacement in text_tests.lua at line 438
    [3.10026][3.668:759](),[3.668][3.668:759]()
    App.screen.check(y, 'm ad', 'F - test_draw_wrapping_text_containing_non_ascii/screen:3')
    [3.10026]
    [3.2452]
    App.screen.check(y, 'I’m ', 'F - test_draw_wrapping_text_containing_non_ascii/screen:3')
  • replacement in text_tests.lua at line 456
    [3.10359][3.472:558](),[3.472][3.472:558]()
    App.screen.check(y, "I'm ada", 'F - test_click_on_wrapping_line/baseline/screen:2')
    [3.10359]
    [3.10360]
    App.screen.check(y, "I'm ad", 'F - test_click_on_wrapping_line/baseline/screen:2')
  • replacement in text_tests.lua at line 462
    [3.10484][3.10484:10571]()
    check_eq(Editor_state.cursor1.pos, 13, 'F - test_click_on_wrapping_line/cursor:pos')
    [3.10484]
    [3.879]
    check_eq(Editor_state.cursor1.pos, 12, 'F - test_click_on_wrapping_line/cursor:pos')
  • replacement in text_tests.lua at line 478
    [2.3529][3.471:596](),[3.10868][3.471:596](),[3.471][3.471:596]()
    App.screen.check(y, "I'm ada", 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/baseline/screen:2')
    [2.3529]
    [3.10869]
    App.screen.check(y, "I'm ad", 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/baseline/screen:2')
  • replacement in text_tests.lua at line 484
    [3.11032][3.11032:11158]()
    check_eq(Editor_state.cursor1.pos, 13, 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/cursor:pos')
    [3.11032]
    [3.982]
    check_eq(Editor_state.cursor1.pos, 12, 'F - test_click_on_wrapping_line_rendered_from_partway_at_top_of_screen/cursor:pos')
  • replacement in text_tests.lua at line 502
    [3.11491][3.1381:1476](),[3.1381][3.1381:1476]()
    App.screen.check(y, "I'm ada", 'F - test_click_past_end_of_wrapping_line/baseline/screen:2')
    [3.11491]
    [3.11492]
    App.screen.check(y, "I'm ad", 'F - test_click_past_end_of_wrapping_line/baseline/screen:2')
  • replacement in text_tests.lua at line 504
    [3.11527][3.1498:1587](),[3.1498][3.1498:1587]()
    App.screen.check(y, 'm', 'F - test_click_past_end_of_wrapping_line/baseline/screen:3')
    [3.11527]
    [3.11528]
    App.screen.check(y, 'am', 'F - test_click_past_end_of_wrapping_line/baseline/screen:3')
  • replacement in text_tests.lua at line 512
    [3.1874][3.2:127](),[3.2457][3.2:127]()
    function test_click_on_wrapping_line_containing_non_ascii()
    io.write('\ntest_click_on_wrapping_line_containing_non_ascii')
    [3.1874]
    [3.127]
    function test_click_past_end_of_wrapping_line_containing_non_ascii()
    io.write('\ntest_click_past_end_of_wrapping_line_containing_non_ascii')
  • replacement in text_tests.lua at line 525
    [2.3799][3.466:572](),[3.12041][3.466:572](),[3.466][3.466:572]()
    App.screen.check(y, 'madam ', 'F - test_click_on_wrapping_line_containing_non_ascii/baseline/screen:1')
    [2.3799]
    [3.12042]
    App.screen.check(y, 'madam ', 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/baseline/screen:1')
  • replacement in text_tests.lua at line 527
    [3.12077][3.594:703](),[3.594][3.594:703]()
    App.screen.check(y, 'I’m ada', 'F - test_click_on_wrapping_line_containing_non_ascii/baseline/screen:2')
    [3.12077]
    [3.12078]
    App.screen.check(y, 'I’m ad', 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/baseline/screen:2')
  • replacement in text_tests.lua at line 529
    [3.12113][3.725:826](),[3.725][3.725:826]()
    App.screen.check(y, 'm', 'F - test_click_on_wrapping_line_containing_non_ascii/baseline/screen:3')
    [3.12113]
    [3.12114]
    App.screen.check(y, 'am', 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/baseline/screen:3')
  • replacement in text_tests.lua at line 534
    [3.981][3.12150:12304]()
    check_eq(Editor_state.cursor1.pos, 15, 'F - test_click_on_wrapping_line_containing_non_ascii/cursor') -- one more than the number of UTF-8 code-points
    [3.981]
    [3.2]
    check_eq(Editor_state.cursor1.pos, 15, 'F - test_click_past_end_of_wrapping_line_containing_non_ascii/cursor') -- one more than the number of UTF-8 code-points
  • edit in text_tests.lua at line 738
    [3.1941][3.1941:2079]()
    edit.run_after_textinput(Editor_state, 'h')
    edit.run_after_textinput(Editor_state, 'i')
    edit.run_after_textinput(Editor_state, 'j')
  • replacement in text_tests.lua at line 741
    [3.16764][3.3027:3096](),[3.3027][3.3027:3096]()
    App.screen.check(y, 'def', 'F - test_edit_wrapping_text/screen:2')
    [3.16764]
    [3.16765]
    App.screen.check(y, 'de', 'F - test_edit_wrapping_text/screen:2')
  • replacement in text_tests.lua at line 743
    [3.16800][3.3118:3188](),[3.3118][3.3118:3188]()
    App.screen.check(y, 'ghij', 'F - test_edit_wrapping_text/screen:3')
    [3.16800]
    [3.3188]
    App.screen.check(y, 'fg', 'F - test_edit_wrapping_text/screen:3')
  • replacement in text_tests.lua at line 1158
    [3.29573][3.15046:15178](),[3.15046][3.15046:15178]()
    App.screen.check(y, 'ghijk', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:3')
    [3.29573]
    [3.15178]
    App.screen.check(y, 'ghij', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/baseline/screen:3')
  • replacement in text_tests.lua at line 1163
    [3.29849][3.29849:29983]()
    check_eq(Editor_state.cursor1.pos, 6, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:pos')
    [3.29849]
    [2.8866]
    check_eq(Editor_state.cursor1.pos, 5, 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/cursor:pos')
  • replacement in text_tests.lua at line 1167
    [3.30049][3.15811:15934](),[3.15811][3.15811:15934]()
    App.screen.check(y, 'ghijk', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:2')
    [3.30049]
    [3.30050]
    App.screen.check(y, 'ghij', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:2')
  • replacement in text_tests.lua at line 1169
    [3.30085][3.15956:16075](),[3.15956][3.15956:16075]()
    App.screen.check(y, 'l', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:3')
    [3.30085]
    [3.16075]
    App.screen.check(y, 'kl', 'F - test_down_arrow_scrolls_down_by_one_screen_line_after_splitting_within_word/screen:3')
  • replacement in text_tests.lua at line 1187
    [3.30531][3.16759:16879](),[3.16759][3.16759:16879]()
    App.screen.check(y, 'ghijk', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:3')
    [3.30531]
    [3.16879]
    App.screen.check(y, 'ghij', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/baseline/screen:3')
  • replacement in text_tests.lua at line 1197
    [3.31187][3.31187:31309]()
    check_eq(Editor_state.cursor1.pos, 6, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:pos')
    [3.31187]
    [2.9082]
    check_eq(Editor_state.cursor1.pos, 5, 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/cursor:pos')
  • replacement in text_tests.lua at line 1199
    [2.9105][3.17842:17953](),[3.31339][3.17842:17953](),[3.17842][3.17842:17953]()
    App.screen.check(y, 'ghijk', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:1')
    [2.9105]
    [3.31340]
    App.screen.check(y, 'ghij', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:1')
  • replacement in text_tests.lua at line 1201
    [3.31375][3.17975:18082](),[3.17975][3.17975:18082]()
    App.screen.check(y, 'l', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:2')
    [3.31375]
    [3.31376]
    App.screen.check(y, 'kl', 'F - test_page_down_followed_by_down_arrow_does_not_scroll_screen_up/screen:2')
  • replacement in text_tests.lua at line 1538
    [3.40880][3.1292:1379](),[3.1292][3.1292:1379]()
    App.screen.check(y, 'ghijk', 'F - test_typing_on_bottom_line_scrolls_down/screen:2')
    [3.40880]
    [3.40881]
    App.screen.check(y, 'ghij', 'F - test_typing_on_bottom_line_scrolls_down/screen:2')
  • replacement in text_tests.lua at line 1540
    [3.40916][3.1401:1484](),[3.1401][3.1401:1484]()
    App.screen.check(y, 'l', 'F - test_typing_on_bottom_line_scrolls_down/screen:3')
    [3.40916]
    [3.2]
    App.screen.check(y, 'kl', 'F - test_typing_on_bottom_line_scrolls_down/screen:3')
  • replacement in text_tests.lua at line 1747
    [2.13063][3.35264:35352](),[3.46441][3.35264:35352](),[3.35264][3.35264:35352]()
    App.screen.check(y, 'ghijk', 'F - test_backspace_can_scroll_up_screen_line/screen:1')
    [2.13063]
    [3.46442]
    App.screen.check(y, 'ghij', 'F - test_backspace_can_scroll_up_screen_line/screen:1')
  • replacement in text_tests.lua at line 1749
    [3.46477][3.35374:35458](),[3.35374][3.35374:35458]()
    App.screen.check(y, 'l', 'F - test_backspace_can_scroll_up_screen_line/screen:2')
    [3.46477]
    [3.46478]
    App.screen.check(y, 'kl', 'F - test_backspace_can_scroll_up_screen_line/screen:2')
  • replacement in text.lua at line 810
    [3.1184][3.7155:7235]()
    function Text.nearest_pos_less_than(line, x) -- x DOES NOT include left margin
    [3.1184]
    [3.7235]
    -- return the nearest index of line (in utf8 code points) which lies entirely
    -- within x pixels of the left margin
    function Text.nearest_pos_less_than(line, x)
    --? print('-- nearest_pos_less_than', line, x)
  • replacement in text.lua at line 818
    [3.7300][3.214:250]()
    local max_x = Text.x(line, len+1)
    [3.7300]
    [3.7344]
    local max_x = Text.x_after(line, len)
  • edit in text.lua at line 823
    [3.7418][3.7418:7436]()
    --? print('--')
  • replacement in text.lua at line 825
    [3.7496][3.251:335]()
    local currxmin = Text.x(line, curr+1)
    local currxmax = Text.x(line, curr+2)
    [3.7496]
    [3.7596]
    local currxmin = Text.x_after(line, curr+1)
    local currxmax = Text.x_after(line, curr+2)
  • edit in text.lua at line 841
    [3.7876]
    [3.7876]
    end
    function Text.x_after(s, pos)
    local offset = Text.offset(s, math.min(pos+1, #s+1))
    local s_before = s:sub(1, offset-1)
    --? print('^'..s_before..'$')
    local text_before = App.newText(love.graphics.getFont(), s_before)
    return App.width(text_before)