port inscript's bugfix to source editor

[?]
Jun 4, 2023, 7:33 PM
5SM6DRHKPLFWQPCZDTVM4ENVENWBYBQ3Q2KYKSWLWYUTOSEPCRLAC

Dependencies

  • [2] KYNGDE2C consistent names in a few more places
  • [3] LIKTH6HM update stale source X-(
  • [4] 7FPELAZB ah, I see the problem
  • [5] GFXWHTE6 mouse wheel support
  • [6] KKMFQDR4 editing source code from within the app
  • [7] B4JEWKWI hide editor cursor while in file navigator
  • [8] OI4FPFIN support drawings in the source editor
  • [9] QJISOCHJ some temporary logging to catch a bug
  • [10] G54H3YG2 get rid of all bifold text
  • [11] 2L5MEZV3 experiment: new edit namespace
  • [12] LDFXFRUO bring a few things in sync between run and source
  • [13] GZ5WULJV switch source side to new screen-line-based render
  • [14] ISOFHXB2 App.width can no longer take a Text
  • [15] KMSL74GA support selections in the source editor
  • [16] LNUHQOGH start passing in Editor_state explicitly
  • [17] 2CK5QI7W make love event names consistent
  • [*] ORRSP7FV deduce test names on failures

Change contents

  • edit in source_text_tests.lua at line 2
    [5.3537]
    [5.3537]
    -- Arguably this should be called source_edit_tests.lua,
    -- but that would mess up the git blame at this point.
  • edit in source_text_tests.lua at line 831
    [19.30265]
    [5.9170]
    end
    function test_select_text_using_mouse_starting_above_text()
    App.screen.init{width=50, height=60}
    Editor_state = edit.initialize_test_state()
    Editor_state.lines = load_array{'abc', 'def', 'xyz'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=1, pos=1}
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.screen_bottom1 = {}
    Editor_state.selection1 = {}
    edit.draw(Editor_state) -- populate line_cache.starty for each line Editor_state.line_cache
    -- press mouse above first line of text
    edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
    check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
    check_eq(Editor_state.selection1.line, 1, 'selection:line')
    check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
  • edit in source_text_tests.lua at line 850
    [5.9175]
    [5.9175]
    function test_select_text_using_mouse_starting_above_text_wrapping_line()
    -- first screen line starts in the middle of a line
    App.screen.init{width=50, height=60}
    Editor_state = edit.initialize_test_state()
    Editor_state.lines = load_array{'abc', 'defgh', 'xyz'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=2, pos=5}
    Editor_state.screen_top1 = {line=2, pos=3}
    Editor_state.screen_bottom1 = {}
    -- press mouse above first line of text
    edit.run_after_mouse_press(Editor_state, Editor_state.left+8,5, 1)
    -- selection is at screen top
    check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
    check_eq(Editor_state.selection1.line, 2, 'selection:line')
    check_eq(Editor_state.selection1.pos, 3, 'selection:pos')
    end
    function test_select_text_using_mouse_starting_below_text()
    -- I'd like to test what happens when a mouse click is below some page of
    -- text, potentially even in the middle of a line.
    -- However, it's brittle to set up a text line boundary just right.
    -- So I'm going to just check things below the bottom of the final line of
    -- text when it's in the middle of the screen.
    -- final screen line ends in the middle of screen
    App.screen.init{width=50, height=60}
    Editor_state = edit.initialize_test_state()
    Editor_state.lines = load_array{'abcde'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=1, pos=1}
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.screen_bottom1 = {}
    edit.draw(Editor_state)
    local y = Editor_state.top
    App.screen.check(y, 'ab', 'baseline:screen:1')
    y = y + Editor_state.line_height
    App.screen.check(y, 'cde', 'baseline:screen:2')
    -- press mouse above first line of text
    edit.run_after_mouse_press(Editor_state, 5,App.screen.height-5, 1)
    -- selection is past bottom-most text in screen
    check(Editor_state.selection1.line ~= nil, 'selection:line-not-nil')
    check_eq(Editor_state.selection1.line, 1, 'selection:line')
    check_eq(Editor_state.selection1.pos, 6, 'selection:pos')
    end
  • edit in source_text_tests.lua at line 946
    [19.30731]
    [5.33133]
    end
    function test_select_all_text()
    -- display a single line of text
    App.screen.init{width=75, height=80}
    Editor_state = edit.initialize_test_state()
    Editor_state.lines = load_array{'abc def'}
    Text.redraw_all(Editor_state)
    Editor_state.cursor1 = {line=1, pos=1}
    Editor_state.screen_top1 = {line=1, pos=1}
    Editor_state.screen_bottom1 = {}
    edit.draw(Editor_state)
    -- select all
    App.fake_key_press('lctrl')
    edit.run_after_keychord(Editor_state, 'C-a')
    App.fake_key_release('lctrl')
    edit.key_release(Editor_state, 'lctrl')
    -- selection
    check_eq(Editor_state.selection1.line, 1, 'selection:line')
    check_eq(Editor_state.selection1.pos, 1, 'selection:pos')
    check_eq(Editor_state.cursor1.line, 1, 'cursor:line')
    check_eq(Editor_state.cursor1.pos, 8, 'cursor:pos')
  • edit in source_text.lua at line 653
    [5.124402]
    [5.124721]
    -- result: pos, index of screen line
  • edit in source_text.lua at line 666
    [5.125077]
    [5.125621]
    function Text.pos_at_end_of_screen_line(State, loc1)
    Text.populate_screen_line_starting_pos(State, loc1.line)
    local line_cache = State.line_cache[loc1.line]
    local most_recent_final_pos = utf8.len(State.lines[loc1.line].data)+1
    for i=#line_cache.screen_line_starting_pos,1,-1 do
    local spos = line_cache.screen_line_starting_pos[i]
    if spos <= loc1.pos then
    return most_recent_final_pos
    end
    most_recent_final_pos = spos-1
    end
    assert(false)
    end
  • edit in source_select.lua at line 2
    [5.23331][5.23331:23478]()
    -- To keep things simple, we'll ignore the B side when selections start on the
    -- A side, and stick to within a single B side selections start in.
  • edit in source_select.lua at line 32
    [5.24908][5.24908:24986]()
    --? print(minl,line_index,maxl, '--', minp,apos,bpos,maxp, '--', a_ge,b_lt)
  • edit in source_select.lua at line 62
    [5.25970][5.25970:26046]()
    --? print(lo,pos,hi, '--', lo_offset,pos_offset,hi_offset, '--', lo_px)
  • edit in source_select.lua at line 70
    [5.26356][5.26356:26418]()
    -- inefficient for some reason, so don't do it on every frame
  • replacement in source_select.lua at line 71
    [5.26449][5.26449:26807]()
    local time = love.timer.getTime()
    if State.recent_mouse.time and State.recent_mouse.time > time-0.1 then
    return State.recent_mouse.line, State.recent_mouse.pos
    end
    State.recent_mouse.time = time
    local line,pos = Text.to_pos(State, App.mouse_x(), App.mouse_y())
    if line then
    State.recent_mouse.line = line
    State.recent_mouse.pos = pos
    [5.26449]
    [5.26807]
    local x,y = App.mouse_x(), App.mouse_y()
    if y < State.line_cache[State.screen_top1.line].starty then
    return State.screen_top1.line, State.screen_top1.pos
  • edit in source_select.lua at line 75
    [5.26813][5.26813:26908]()
    return State.recent_mouse.line, State.recent_mouse.pos
    end
    function Text.to_pos(State, x,y)
  • edit in source_select.lua at line 82
    [5.27134]
    [5.27134]
    return State.screen_bottom1.line, Text.pos_at_end_of_screen_line(State, State.screen_bottom1)
  • edit in source_edit.lua at line 79
    [5.30270][5.30270:30372]()
    -- when selecting text, avoid recomputing some state on every single frame
    recent_mouse = {},
  • edit in source_edit.lua at line 156
    [5.155762]
    [5.155762]
    local screen_bottom1 = {line=nil, pos=nil}
  • replacement in source_edit.lua at line 162
    [5.155992][5.6552:6606]()
    State.screen_bottom1 = {line=line_index, pos=nil}
    [5.155992]
    [5.19945]
    screen_bottom1.line = line_index
  • replacement in source_edit.lua at line 185
    [5.156342][5.6719:6810]()
    y, State.screen_bottom1.pos = Text.draw(State, line_index, y, startpos, hide_cursor)
    [5.156342]
    [5.21245]
    y, screen_bottom1.pos = Text.draw(State, line_index, y, startpos, hide_cursor)
  • edit in source_edit.lua at line 196
    [5.156525]
    [5.156525]
    State.screen_bottom1 = screen_bottom1
  • replacement in source_edit.lua at line 227
    [5.157151][3.395:436]()
    --? print('press', State.cursor1.line)
    [5.157151]
    [5.157217]
    --? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  • edit in source_edit.lua at line 233
    [5.157379]
    [5.157379]
    if y < State.top then
    State.old_cursor1 = State.cursor1
    State.old_selection1 = State.selection1
    State.mousepress_shift = App.shift_down()
    State.selection1 = {
    line=State.screen_top1.line,
    pos=State.screen_top1.pos,
    }
    return
    end
  • edit in source_edit.lua at line 256
    [5.2433]
    [5.30898]
    --? print_and_log(('edit.mouse_press: in line %d'):format(line_index))
  • replacement in source_edit.lua at line 264
    [5.6941][5.6941:7017](),[5.7017][5.21843:21857](),[5.31203][5.21843:21857](),[5.21843][5.21843:21857]()
    --? print('selection', State.selection1.line, State.selection1.pos)
    break
    [5.6941]
    [5.21857]
    return
  • replacement in source_edit.lua at line 273
    [2.130][5.22260:22274](),[5.22260][5.22260:22274]()
    break
    [2.130]
    [5.22274]
    return
  • edit in source_edit.lua at line 277
    [5.157693]
    [5.157693]
    -- still here? click is below all screen lines
    State.old_cursor1 = State.cursor1
    State.old_selection1 = State.selection1
    State.mousepress_shift = App.shift_down()
    State.selection1 = {
    line=State.screen_bottom1.line,
    pos=Text.pos_at_end_of_screen_line(State, State.screen_bottom1),
    }
  • replacement in source_edit.lua at line 290
    [5.22324][3.437:480]()
    --? print('release', State.cursor1.line)
    [5.22324]
    [5.22347]
    --? print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  • edit in source_edit.lua at line 299
    [5.31211]
    [5.31211]
    --? print_and_log('edit.mouse_release: no current drawing')
  • replacement in source_edit.lua at line 303
    [5.31348][5.31348:31387]()
    --? print('reset selection')
    [5.31348]
    [5.7018]
    --? print_and_log(('edit.mouse_release: in line %d'):format(line_index))
  • replacement in source_edit.lua at line 308
    [5.7153][5.7153:7222]()
    --? print('cursor', State.cursor1.line, State.cursor1.pos)
    [5.7153]
    [5.31612]
    --? print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  • replacement in source_edit.lua at line 324
    [5.32086][5.32086:32159]()
    --? print('selection:', State.selection1.line, State.selection1.pos)
    [5.32086]
    [5.11]
    --? print_and_log(('edit.mouse_release: finally selection %s,%s cursor %d,%d'):format(tostring(State.selection1.line), tostring(State.selection1.pos), State.cursor1.line, State.cursor1.pos))
  • edit in source.lua at line 116
    [5.168401]
    [5.168401]
    function print_and_log(s)
    print(s)
    log(3, s)
    end
  • replacement in edit.lua at line 255
    [5.5449][4.254:329]()
    print_and_log(('edit.mouse_press: in line %d'):format(line_index))
    [5.5449]
    [5.4792]
    --? print_and_log(('edit.mouse_press: in line %d'):format(line_index))