Merge lines.love

[?]
Apr 2, 2023, 6:10 AM
OEIR7M74D747NZME7BK6YHKHNBIYLVE6HD7FZN2HITFF7MX4JLUAC

Dependencies

  • [2] 6K5PFF6X helper: trimming whitespace from strings
  • [3] KGBSEDPF Merge lines.love
  • [4] I64IPGJX avoid saving fragments in lines
  • [5] ISOFHXB2 App.width can no longer take a Text
  • [6] Z4XRNDTR find text
  • [7] H4R5BHVY no more Text allocations
  • [8] VG34LDWY experiment: simple hyperlinks just to local files
  • [9] X3F7ECSL add state arg to some functions
  • [10] S2QMLRXL stop creating a singleton table for every word
  • [11] 6WDBV52Z move a var closer to its use
  • [12] HALS7E5U more clearly skip prints before screen top
  • [13] WLHI7KD3 new globals: draw partial screen line up top
  • [14] DHI6IJCN selecting text and deleting selections
  • [15] LERERVPH keep one screen line of overlap on pagedown
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] V5SYDHPQ start thinking of compute_fragments as a detail
  • [*] PFT5Y2ZY move
  • [*] 2CK5QI7W make love event names consistent
  • [*] TGHAJBES use line cache for drawings as well

Change contents

  • edit in text.lua at line 15
    [18.63]
    [4.162]
    Text.populate_link_offsets(State, line_index)
  • edit in text.lua at line 27
    [4.521][5.3:28](),[5.138][5.3:28]()
    -- render fragment
  • resurrect zombie in text.lua at line 27
    [5.258][5.3:13](),[5.258][5.3:13]()
    end
  • edit in text.lua at line 27
    [4.521]
    [5.3]
    -- render any link decorations
    for _,link_offsets in ipairs(line_cache.link_offsets) do
    local s,e,filename = unpack(link_offsets)
    local lo, hi = Text.clip_filename_with_screen_line(line, line_cache, i, s, e)
    if lo then
    button(State, 'link', {x=State.left+lo, y=y, w=hi-lo, h=State.line_height, color={1,1,1},
    icon = icon.hyperlink_decoration,
    onpress1 = function()
    run.switch_to_file(filename)
    end,
    })
    end
  • replacement in text.lua at line 40
    [5.13][5.13:505](),[5.13][5.13:505](),[5.505][3.3:81](),[3.81][5.580:591](),[5.580][5.580:591](),[5.580][5.580:591]()
    -- If fragment is a filename relative to the current directory, register
    -- a button for clicks on it.
    local filename = rtrim(frag) -- compute_fragments puts whitespace at the end
    if file_exists(filename) then
    local filename_text = App.newText(love.graphics.getFont(), filename)
    button(State, 'link', {x=x,y=y, w=App.width(filename_text), h=State.line_height, color={1,1,1},
    icon = icon.hyperlink_decoration,
    onpress1 = function()
    run.switch_to_file(filename)
    end,
    })
    [5.13]
    [5.629]
    -- render fragment
  • edit in text.lua at line 127
    [4.2237]
    [19.1557]
    end
    end
    function Text.populate_link_offsets(State, line_index)
    local line = State.lines[line_index]
    if line.mode ~= 'text' then return end
    local line_cache = State.line_cache[line_index]
    if line_cache.link_offsets then
    return
    end
    line_cache.link_offsets = {}
    local pos = 1
    -- try to wrap at word boundaries
    local s, e = 1, 0
    while s <= #line.data do
    s, e = line.data:find('%w+', s)
    if s == nil then break end
    local word = line.data:sub(s, e)
    if file_exists(word) then
    --? print('filename:', s, e, word)
    table.insert(line_cache.link_offsets, {s, e, word})
    end
    s = e + 1
  • edit in text.lua at line 153
    [19.1568]
    [20.1034]
    -- Intersect the filename between byte offsets s,e with the bounds of screen line i.
    -- Return the left/right pixel coordinates of of the intersection,
    -- or nil if it doesn't intersect with screen line i.
    function Text.clip_filename_with_screen_line(line, line_cache, i, s, e)
    local spos = line_cache.screen_line_starting_pos[i]
    local soff = Text.offset(line.data, spos)
    if e < soff then
    return
    end
    local eoff
    if i < #line_cache.screen_line_starting_pos then
    local epos = line_cache.screen_line_starting_pos[i+1]
    eoff = Text.offset(line.data, epos)
    if s > eoff then
    return
    end
    end
    local loff = math.max(s, soff)
    local hoff
    if eoff then
    hoff = math.min(e, eoff)
    else
    hoff = e
    end
    --? print(s, e, soff, eoff, loff, hoff)
    return App.width(line.data:sub(1, loff-1)), App.width(line.data:sub(1, hoff))
    end
  • edit in text.lua at line 1023
    [21.1777]
    [2.3]
    State.line_cache[line_index].link_offsets = nil