support hyperlinks in the source editor
Integrated from the pensieve fork.
This commit is contained in:
parent
fdb35ce12b
commit
516944b572
|
@ -8,6 +8,12 @@ function icon.insert_drawing(button_params)
|
||||||
love.graphics.line(10,y, 10,y+12)
|
love.graphics.line(10,y, 10,y+12)
|
||||||
end
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
function icon.freehand(x, y)
|
function icon.freehand(x, y)
|
||||||
love.graphics.line(x+4,y+7,x+5,y+5)
|
love.graphics.line(x+4,y+7,x+5,y+5)
|
||||||
love.graphics.line(x+5,y+5,x+7,y+4)
|
love.graphics.line(x+5,y+5,x+7,y+4)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
-- some constants people might like to tweak
|
-- some constants people might like to tweak
|
||||||
Text_color = {r=0, g=0, b=0}
|
Text_color = {r=0, g=0, b=0}
|
||||||
Cursor_color = {r=1, g=0, b=0}
|
Cursor_color = {r=1, g=0, b=0}
|
||||||
|
Hyperlink_decoration_color = {r=0.4, g=0.4, b=1}
|
||||||
Stroke_color = {r=0, g=0, b=0}
|
Stroke_color = {r=0, g=0, b=0}
|
||||||
Current_stroke_color = {r=0.7, g=0.7, b=0.7} -- in process of being drawn
|
Current_stroke_color = {r=0.7, g=0.7, b=0.7} -- in process of being drawn
|
||||||
Current_name_background_color = {r=1, g=0, b=0, a=0.1} -- name currently being edited
|
Current_name_background_color = {r=1, g=0, b=0, a=0.1} -- name currently being edited
|
||||||
|
|
|
@ -110,6 +110,20 @@ function Text.draw_wrapping_line(State, line_index, x,y, startpos)
|
||||||
screen_line_starting_pos = pos
|
screen_line_starting_pos = pos
|
||||||
x = State.left
|
x = State.left
|
||||||
end
|
end
|
||||||
|
-- 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
|
||||||
App.screen.draw(frag_text, x,y)
|
App.screen.draw(frag_text, x,y)
|
||||||
-- render cursor if necessary
|
-- render cursor if necessary
|
||||||
if State.cursor1.pos and line_index == State.cursor1.line then
|
if State.cursor1.pos and line_index == State.cursor1.line then
|
||||||
|
@ -1610,12 +1624,23 @@ function Text.cursor_out_of_screen(State)
|
||||||
--? return Text.lt1(State.screen_bottom1, botline1)
|
--? return Text.lt1(State.screen_bottom1, botline1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
function Text.redraw_all(State)
|
function Text.redraw_all(State)
|
||||||
--? print('clearing fragments')
|
--? print('clearing fragments')
|
||||||
State.line_cache = {}
|
State.line_cache = {}
|
||||||
for i=1,#State.lines do
|
for i=1,#State.lines do
|
||||||
State.line_cache[i] = {}
|
State.line_cache[i] = {}
|
||||||
end
|
end
|
||||||
|
State.link_cache = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Text.clear_screen_line_cache(State, line_index)
|
function Text.clear_screen_line_cache(State, line_index)
|
||||||
|
@ -1636,3 +1661,11 @@ end
|
||||||
function rtrim(s)
|
function rtrim(s)
|
||||||
return s:gsub('%s+$', '')
|
return s:gsub('%s+$', '')
|
||||||
end
|
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
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue