add state arg to a few functions

[?]
Jul 12, 2022, 11:43 PM
S2MISTTMPEULTO6WRO4Q4NRUO7XC2PTZW3UBR7K7SO6JPZO6HBHAC

Dependencies

  • [2] X3F7ECSL add state arg to some functions
  • [3] PTDO2SOT add state arg to schedule_save
  • [4] JFFUF5AL override mouse state lookups in tests
  • [5] MP2TBKU6 bugfix: crash in Text.up() after return
  • [6] PLKNHYZ4 extract a function
  • [7] LXTTOB33 extract a couple of files
  • [8] FHSZYAZ2 more precise search highlighting
  • [9] XNFTJHC4 split keyboard handling between Text and Drawing
  • [10] O7QH4N4W speeding up copy, attempt 1
  • [11] 4CXVIEBS add args to some functions
  • [12] DHI6IJCN selecting text and deleting selections
  • [13] OP643FFG move
  • [14] YW5324Q3 bugfix: cut (C-x) without first selecting anything
  • [15] HIKLULFQ extract a function
  • [16] 2TQR4PSY add args to some functions
  • [17] 4J2L6JMR bugfix: deleting a selection spanning pages
  • [18] 4KC7I3E2 make colors easier to edit
  • [19] PX7DDEMO autosave slightly less aggressively
  • [20] AYE2VEGJ extract a couple of methods
  • [21] LF7BWEG4 group all editor globals
  • [22] DRFE3B3Z mouse buttons are integers, not strings
  • [23] LNUHQOGH start passing in Editor_state explicitly
  • [24] SPSW74Y5 add state arg to Text.keychord_pressed
  • [25] JRGTJ2IW quite the frustrating bugfix
  • [26] 2L5MEZV3 experiment: new edit namespace
  • [*] BULPIBEG beginnings of a module for the text editor

Change contents

  • replacement in text.lua at line 50
    [2.665][4.3:90](),[4.54769][4.3:90](),[4.68][4.3:90](),[4.90][4.3:54](),[4.142][4.3:54]()
    local lo, hi = Text.clip_selection(line_index, pos, pos+frag_len, left, right)
    Text.draw_highlight(line, x,y, pos, lo,hi)
    [2.665]
    [4.1056]
    local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len, left, right)
    Text.draw_highlight(State, line, x,y, pos, lo,hi)
  • replacement in text.lua at line 185
    [4.1225][4.1225:1309]()
    Text.delete_selection(State.margin_left, App.screen.width-State.margin_right)
    [4.1225]
    [3.55]
    Text.delete_selection(State, State.margin_left, App.screen.width-State.margin_right)
  • replacement in text.lua at line 226
    [4.2976][4.2976:3060]()
    Text.delete_selection(State.margin_left, App.screen.width-State.margin_right)
    [4.2976]
    [3.109]
    Text.delete_selection(State, State.margin_left, App.screen.width-State.margin_right)
  • replacement in select.lua at line 3
    [4.44053][4.78624:78722]()
    -- Return any intersection of the region from Editor_state.selection1 to Editor_state.cursor1 (or
    [4.44053]
    [4.44125]
    -- Return any intersection of the region from State.selection1 to State.cursor1 (or
  • replacement in select.lua at line 7
    [4.44321][4.78723:78833]()
    -- apos must be less than bpos. However Editor_state.selection1 and Editor_state.cursor1 can be in any order.
    [4.44321]
    [4.44405]
    -- apos must be less than bpos. However State.selection1 and State.cursor1 can be in any order.
  • replacement in select.lua at line 9
    [4.44455][4.239:305](),[4.305][4.78834:79044]()
    function Text.clip_selection(line_index, apos, bpos, left, right)
    if Editor_state.selection1.line == nil then return nil,nil end
    -- min,max = sorted(Editor_state.selection1,Editor_state.cursor1)
    local minl,minp = Editor_state.selection1.line,Editor_state.selection1.pos
    [4.44455]
    [4.44653]
    function Text.clip_selection(State, line_index, apos, bpos, left, right)
    if State.selection1.line == nil then return nil,nil end
    -- min,max = sorted(State.selection1,State.cursor1)
    local minl,minp = State.selection1.line,State.selection1.pos
  • replacement in select.lua at line 15
    [4.1213][4.306:350]()
    maxl,maxp = Text.mouse_pos(left, right)
    [4.1213]
    [4.44737]
    maxl,maxp = Text.mouse_pos(State, left, right)
  • replacement in select.lua at line 17
    [4.44744][4.79045:79112]()
    maxl,maxp = Editor_state.cursor1.line,Editor_state.cursor1.pos
    [4.44744]
    [4.44785]
    maxl,maxp = State.cursor1.line,State.cursor1.pos
  • replacement in select.lua at line 54
    [4.291][4.177:229](),[4.177][4.177:229]()
    function Text.draw_highlight(line, x,y, pos, lo,hi)
    [4.291]
    [4.229]
    function Text.draw_highlight(State, line, x,y, pos, lo,hi)
  • replacement in select.lua at line 72
    [4.152][4.79113:79197]()
    love.graphics.rectangle('fill', x+lo_px,y, text_width,Editor_state.line_height)
    [4.152]
    [4.153]
    love.graphics.rectangle('fill', x+lo_px,y, text_width,State.line_height)
  • replacement in select.lua at line 79
    [4.45876][4.351:388]()
    function Text.mouse_pos(left, right)
    [4.45876]
    [4.45902]
    function Text.mouse_pos(State, left, right)
  • replacement in select.lua at line 81
    [4.45938][4.79198:79358]()
    if Editor_state.recent_mouse.time and Editor_state.recent_mouse.time > time-0.1 then
    return Editor_state.recent_mouse.line, Editor_state.recent_mouse.pos
    [4.45938]
    [4.46046]
    if State.recent_mouse.time and State.recent_mouse.time > time-0.1 then
    return State.recent_mouse.line, State.recent_mouse.pos
  • replacement in select.lua at line 84
    [4.46052][4.79359:79399](),[4.79399][4.389:463](),[4.46079][4.389:463]()
    Editor_state.recent_mouse.time = time
    local line,pos = Text.to_pos(App.mouse_x(), App.mouse_y(), left, right)
    [4.46052]
    [4.46148]
    State.recent_mouse.time = time
    local line,pos = Text.to_pos(State, App.mouse_x(), App.mouse_y(), left, right)
  • replacement in select.lua at line 87
    [4.46163][4.79400:79482]()
    Editor_state.recent_mouse.line = line
    Editor_state.recent_mouse.pos = pos
    [4.46163]
    [4.46219]
    State.recent_mouse.line = line
    State.recent_mouse.pos = pos
  • replacement in select.lua at line 90
    [4.46225][4.79483:79554]()
    return Editor_state.recent_mouse.line, Editor_state.recent_mouse.pos
    [4.46225]
    [4.46270]
    return State.recent_mouse.line, State.recent_mouse.pos
  • replacement in select.lua at line 93
    [4.46275][4.464:503](),[4.503][4.79555:79610]()
    function Text.to_pos(x,y, left, right)
    for line_index,line in ipairs(Editor_state.lines) do
    [4.46275]
    [4.46343]
    function Text.to_pos(State, x,y, left, right)
    for line_index,line in ipairs(State.lines) do
  • replacement in select.lua at line 103
    [4.10][4.504:545](),[4.545][4.79611:79668](),[4.49][4.40:74](),[4.79668][4.40:74](),[4.40][4.40:74](),[4.74][4.546:583]()
    function Text.cut_selection(left, right)
    if Editor_state.selection1.line == nil then return end
    local result = Text.selection()
    Text.delete_selection(left, right)
    [4.10]
    [4.100]
    function Text.cut_selection(State, left, right)
    if State.selection1.line == nil then return end
    local result = Text.selection(State)
    Text.delete_selection(State, left, right)
  • replacement in select.lua at line 110
    [4.46500][4.584:628](),[4.628][4.79669:79810]()
    function Text.delete_selection(left, right)
    if Editor_state.selection1.line == nil then return end
    local minl,maxl = minmax(Editor_state.selection1.line, Editor_state.cursor1.line)
    [4.46500]
    [4.46591]
    function Text.delete_selection(State, left, right)
    if State.selection1.line == nil then return end
    local minl,maxl = minmax(State.selection1.line, State.cursor1.line)
  • replacement in select.lua at line 114
    [4.46629][4.629:679](),[4.679][4.79811:79891]()
    Text.delete_selection_without_undo(left, right)
    record_undo_event({before=before, after=snapshot(Editor_state.cursor1.line)})
    [4.46629]
    [4.46735]
    Text.delete_selection_without_undo(State, left, right)
    record_undo_event({before=before, after=snapshot(State.cursor1.line)})
  • replacement in select.lua at line 118
    [4.46740][4.680:737](),[4.737][4.79892:80165]()
    function Text.delete_selection_without_undo(left, right)
    if Editor_state.selection1.line == nil then return end
    -- min,max = sorted(Editor_state.selection1,Editor_state.cursor1)
    local minl,minp = Editor_state.selection1.line,Editor_state.selection1.pos
    local maxl,maxp = Editor_state.cursor1.line,Editor_state.cursor1.pos
    [4.46740]
    [4.46968]
    function Text.delete_selection_without_undo(State, left, right)
    if State.selection1.line == nil then return end
    -- min,max = sorted(State.selection1,State.cursor1)
    local minl,minp = State.selection1.line,State.selection1.pos
    local maxl,maxp = State.cursor1.line,State.cursor1.pos
  • replacement in select.lua at line 131
    [4.47135][4.80166:80515]()
    -- update Editor_state.cursor1 and Editor_state.selection1
    Editor_state.cursor1.line = minl
    Editor_state.cursor1.pos = minp
    if Text.lt1(Editor_state.cursor1, Editor_state.screen_top1) then
    Editor_state.screen_top1.line = Editor_state.cursor1.line
    _,Editor_state.screen_top1.pos = Text.pos_at_start_of_cursor_screen_line(left, right)
    [4.47135]
    [4.1160]
    -- update State.cursor1 and State.selection1
    State.cursor1.line = minl
    State.cursor1.pos = minp
    if Text.lt1(State.cursor1, State.screen_top1) then
    State.screen_top1.line = State.cursor1.line
    _,State.screen_top1.pos = Text.pos_at_start_of_cursor_screen_line(left, right)
  • replacement in select.lua at line 138
    [4.1166][4.80516:80547]()
    Editor_state.selection1 = {}
    [4.1166]
    [4.47231]
    State.selection1 = {}
  • replacement in select.lua at line 140
    [4.47298][4.80548:80733]()
    Text.clear_cache(Editor_state.lines[minl])
    local min_offset = Text.offset(Editor_state.lines[minl].data, minp)
    local max_offset = Text.offset(Editor_state.lines[maxl].data, maxp)
    [4.47298]
    [4.47487]
    Text.clear_cache(State.lines[minl])
    local min_offset = Text.offset(State.lines[minl].data, minp)
    local max_offset = Text.offset(State.lines[maxl].data, maxp)
  • replacement in select.lua at line 145
    [4.47540][4.80734:80868]()
    Editor_state.lines[minl].data = Editor_state.lines[minl].data:sub(1, min_offset-1)..Editor_state.lines[minl].data:sub(max_offset)
    [4.47540]
    [4.47635]
    State.lines[minl].data = State.lines[minl].data:sub(1, min_offset-1)..State.lines[minl].data:sub(max_offset)
  • replacement in select.lua at line 149
    [4.47674][4.80869:80929]()
    local rhs = Editor_state.lines[maxl].data:sub(max_offset)
    [4.47674]
    [4.47721]
    local rhs = State.lines[maxl].data:sub(max_offset)
  • replacement in select.lua at line 151
    [4.47747][4.80930:80970]()
    table.remove(Editor_state.lines, i)
    [4.47747]
    [4.47774]
    table.remove(State.lines, i)
  • replacement in select.lua at line 153
    [4.47780][4.80971:81061]()
    Editor_state.lines[minl].data = Editor_state.lines[minl].data:sub(1, min_offset-1)..rhs
    [4.47780]
    [4.47844]
    State.lines[minl].data = State.lines[minl].data:sub(1, min_offset-1)..rhs
  • replacement in select.lua at line 156
    [4.47849][4.47849:47875](),[4.47875][4.81062:81335]()
    function Text.selection()
    if Editor_state.selection1.line == nil then return end
    -- min,max = sorted(Editor_state.selection1,Editor_state.cursor1)
    local minl,minp = Editor_state.selection1.line,Editor_state.selection1.pos
    local maxl,maxp = Editor_state.cursor1.line,Editor_state.cursor1.pos
    [4.47849]
    [4.48057]
    function Text.selection(State)
    if State.selection1.line == nil then return end
    -- min,max = sorted(State.selection1,State.cursor1)
    local minl,minp = State.selection1.line,State.selection1.pos
    local maxl,maxp = State.cursor1.line,State.cursor1.pos
  • replacement in select.lua at line 169
    [4.48224][4.81336:81476]()
    local min_offset = Text.offset(Editor_state.lines[minl].data, minp)
    local max_offset = Text.offset(Editor_state.lines[maxl].data, maxp)
    [4.48224]
    [4.48338]
    local min_offset = Text.offset(State.lines[minl].data, minp)
    local max_offset = Text.offset(State.lines[maxl].data, maxp)
  • replacement in select.lua at line 172
    [4.48361][4.81477:81548]()
    return Editor_state.lines[minl].data:sub(min_offset, max_offset-1)
    [4.48361]
    [4.48419]
    return State.lines[minl].data:sub(min_offset, max_offset-1)
  • replacement in select.lua at line 175
    [4.48447][4.81549:81614]()
    local result = {Editor_state.lines[minl].data:sub(min_offset)}
    [4.48447]
    [4.48503]
    local result = {State.lines[minl].data:sub(min_offset)}
  • replacement in select.lua at line 177
    [4.48528][4.81615:81719]()
    if Editor_state.lines[i].mode == 'text' then
    table.insert(result, Editor_state.lines[i].data)
    [4.48528]
    [4.48607]
    if State.lines[i].mode == 'text' then
    table.insert(result, State.lines[i].data)
  • replacement in select.lua at line 181
    [4.48621][4.81720:81795]()
    table.insert(result, Editor_state.lines[maxl].data:sub(1, max_offset-1))
    [4.48621]
    [4.163]
    table.insert(result, State.lines[maxl].data:sub(1, max_offset-1))
  • replacement in edit.lua at line 302
    [4.10886][4.6874:6956]()
    Text.delete_selection(State.margin_left, App.screen.width-State.margin_right)
    [4.10886]
    [4.10956]
    Text.delete_selection(State, State.margin_left, App.screen.width-State.margin_right)
  • replacement in edit.lua at line 368
    [4.8507][4.13320:13351](),[4.104726][4.13320:13351](),[4.13320][4.13320:13351]()
    local s = Text.selection()
    [4.8507]
    [4.13351]
    local s = Text.selection(State)
  • replacement in edit.lua at line 374
    [4.8593][4.8593:8682]()
    local s = Text.cut_selection(State.margin_left, App.screen.width-State.margin_right)
    [4.8593]
    [4.13588]
    local s = Text.cut_selection(State, State.margin_left, App.screen.width-State.margin_right)