support hyperlinks in the source editor

[?]
Sep 5, 2022, 9:16 PM
UN7GKYV5YP5DQRKDYNYJTGX3CPXQYBVFJ7SLW44NWCN53VEZ3GAAC

Dependencies

  • [2] OI4FPFIN support drawings in the source editor
  • [*] KKMFQDR4 editing source code from within the app
  • [*] VHQCNMAR several more modules

Change contents

  • edit in source_text.lua at line 113
    [4.88189]
    [4.88189]
    -- Make [[WikiWords]] (single word, all in one screen line) clickable.
    local trimmed_word = rtrim(frag) -- compute_fragments puts whitespace at the end
    if starts_with(trimmed_word, '[[') and ends_with(trimmed_word, ']]') then
    local filename = trimmed_word:gsub('^..(.*)..$', '%1')
    if source.link_exists(State, filename) then
    local filename_text = App.newText(love.graphics.getFont(), filename)
    button(State, 'link', {x=x+App.width(to_text('[[')), y=y, w=App.width(filename_text), h=State.line_height, color={1,1,1},
    icon = icon.hyperlink_decoration,
    onpress1 = function()
    source.switch_to_file(filename)
    end,
    })
    end
    end
  • edit in source_text.lua at line 1627
    [4.146455]
    [4.146455]
    function source.link_exists(State, filename)
    if State.link_cache == nil then
    State.link_cache = {}
    end
    if State.link_cache[filename] == nil then
    State.link_cache[filename] = file_exists(filename)
    end
    return State.link_cache[filename]
    end
  • edit in source_text.lua at line 1643
    [4.146606]
    [4.146606]
    State.link_cache = {}
  • edit in source_text.lua at line 1663
    [4.147057]
    [4.147057]
    end
    function starts_with(s, sub)
    return s:find(sub, 1, --[[no escapes]] true) == 1
    end
    function ends_with(s, sub)
    return s:reverse():find(sub:reverse(), 1, --[[no escapes]] true) == 1
  • edit in source_edit.lua at line 4
    [4.152546]
    [2.17840]
    Hyperlink_decoration_color = {r=0.4, g=0.4, b=1}
  • edit in icons.lua at line 9
    [5.5526]
    [5.5560]
    end
    function icon.hyperlink_decoration(button_params)
    local x,y = button_params.x, button_params.y
    App.color(Hyperlink_decoration_color)
    love.graphics.line(x,y+Editor_state.line_height, x+button_params.w,y+Editor_state.line_height)