more robust state validation

[?]
Mar 17, 2023, 4:36 PM
7VGDIPLCFDG3PVE4JH3WDKZ4A7PG5UYW7TLFFFOWN2JEUZYYTFJQC

Dependencies

  • [2] KKMFQDR4 editing source code from within the app
  • [3] CQYKYJJU remember window positions across restart/ctrl+e
  • [4] LF7BWEG4 group all editor globals
  • [5] 2L5MEZV3 experiment: new edit namespace
  • [6] EMG7SDLW bugfix: cold start
  • [7] LNUHQOGH start passing in Editor_state explicitly
  • [8] 4KC7I3E2 make colors easier to edit
  • [9] QZ2SXLHF some debug prints
  • [10] 5STHSG4U remove some duplication
  • [11] ERQKFTPV extract method
  • [12] 2CK5QI7W make love event names consistent
  • [13] HCFDBUXH fix stale comment

Change contents

  • edit in run.lua at line 31
    [2.178847][2.178847:178883]()
    edit.fixup_cursor(Editor_state)
  • edit in run.lua at line 34
    [2.178957][2.178957:179127]()
    if Editor_state.cursor1.line > #Editor_state.lines or Editor_state.lines[Editor_state.cursor1.line].mode ~= 'text' then
    edit.fixup_cursor(Editor_state)
    end
  • edit in run.lua at line 35
    [2.179133]
    [2.179133]
    edit.check_locs(Editor_state)
  • replacement in run.lua at line 112
    [2.182195][2.182195:182229]()
    edit.fixup_cursor(Editor_state)
    [2.182195]
    [2.182229]
    edit.check_locs(Editor_state)
  • replacement in edit.lua at line 112
    [3.3868][3.89:123]()
    function edit.fixup_cursor(State)
    [3.3868]
    [3.221]
    function edit.check_locs(State)
    -- if State is inconsistent (i.e. file changed by some other program),
    -- throw away all cursor state entirely
    if edit.invalid1(State, State.screen_top1)
    or edit.invalid1(State, State.cursor1)
    or not edit.cursor_on_text(State)
    or not Text.le1(State.screen_top1, State.cursor1) then
    State.screen_top1 = {line=1, pos=1}
    edit.put_cursor_on_first_text_line(State)
    end
    end
    function edit.invalid1(State, loc1)
    return loc1.line > #State.lines
    or loc1.pos > #State.lines[loc1.line].data
    end
    function edit.cursor_on_text(State)
    return State.cursor1.line <= #State.lines
    and State.lines[State.cursor1.line].mode == 'text'
    end
    function edit.put_cursor_on_first_text_line(State)
  • replacement in edit.lua at line 137
    [3.292][3.292:321]()
    State.cursor1.line = i
    [3.292]
    [3.321]
    State.cursor1 = {line=i, pos=1}