stop creating a singleton table for every word
This commit is contained in:
parent
fbc8b85bcf
commit
ed27b8dd85
|
@ -17,15 +17,15 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
|
|||
initialize_color()
|
||||
for _, f in ipairs(line_cache.fragments) do
|
||||
App.color(Text_color)
|
||||
select_color(f.data)
|
||||
local frag_len = utf8.len(f.data)
|
||||
--? print('text.draw:', f.data, 'at', line_index,pos, 'after', x,y)
|
||||
select_color(f)
|
||||
local frag_len = utf8.len(f)
|
||||
--? print('text.draw:', f, 'at', line_index,pos, 'after', x,y)
|
||||
if pos < startpos then
|
||||
-- render nothing
|
||||
--? print('skipping', f.data)
|
||||
--? print('skipping', f)
|
||||
else
|
||||
-- render fragment
|
||||
local frag_width = App.width(f.data)
|
||||
local frag_width = App.width(f)
|
||||
if x + frag_width > State.right then
|
||||
assert(x > State.left) -- no overfull lines
|
||||
y = y + State.line_height
|
||||
|
@ -40,7 +40,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
|
|||
Text.draw_highlight(State, line, x,y, pos, lo,hi)
|
||||
end
|
||||
-- Make [[WikiWords]] (single word, all in one screen line) clickable.
|
||||
local trimmed_word = rtrim(f.data) -- compute_fragments puts whitespace at the end
|
||||
local trimmed_word = rtrim(f) -- 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
|
||||
|
@ -52,7 +52,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
|
|||
})
|
||||
end
|
||||
end
|
||||
App.screen.print(f.data, x,y)
|
||||
App.screen.print(f, x,y)
|
||||
-- render cursor if necessary
|
||||
if line_index == State.cursor1.line then
|
||||
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then
|
||||
|
@ -63,7 +63,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
|
|||
love.graphics.print(State.search_term, x+lo_px,y)
|
||||
end
|
||||
elseif Focus == 'edit' then
|
||||
Text.draw_cursor(State, x+Text.x(f.data, State.cursor1.pos-pos+1), y)
|
||||
Text.draw_cursor(State, x+Text.x(f, State.cursor1.pos-pos+1), y)
|
||||
App.color(Text_color)
|
||||
end
|
||||
end
|
||||
|
@ -104,13 +104,13 @@ function Text.populate_screen_line_starting_pos(State, line_index)
|
|||
local pos = 1
|
||||
for _, f in ipairs(line_cache.fragments) do
|
||||
-- render fragment
|
||||
local frag_width = App.width(f.data)
|
||||
local frag_width = App.width(f)
|
||||
if x + frag_width > State.right then
|
||||
x = State.left
|
||||
table.insert(line_cache.screen_line_starting_pos, pos)
|
||||
end
|
||||
x = x + frag_width
|
||||
pos = pos + utf8.len(f.data)
|
||||
pos = pos + utf8.len(f)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -136,14 +136,14 @@ function Text.compute_fragments(State, line_index)
|
|||
local frag1 = string.sub(frag, 1, boffset-1)
|
||||
local frag1_width = App.width(frag1)
|
||||
assert(x + frag1_width <= State.right)
|
||||
table.insert(line_cache.fragments, {data=frag1})
|
||||
table.insert(line_cache.fragments, frag1)
|
||||
frag = string.sub(frag, boffset)
|
||||
frag_width = App.width(frag)
|
||||
end
|
||||
x = State.left -- new line
|
||||
end
|
||||
if #frag > 0 then
|
||||
table.insert(line_cache.fragments, {data=frag})
|
||||
table.insert(line_cache.fragments, frag)
|
||||
end
|
||||
x = x + frag_width
|
||||
end
|
||||
|
|
20
text.lua
20
text.lua
|
@ -15,14 +15,14 @@ function Text.draw(State, line_index, y, startpos)
|
|||
Text.compute_fragments(State, line_index)
|
||||
for _, f in ipairs(line_cache.fragments) do
|
||||
App.color(Text_color)
|
||||
local frag_len = utf8.len(f.data)
|
||||
--? print('text.draw:', f.data, 'at', line_index,pos, 'after', x,y)
|
||||
local frag_len = utf8.len(f)
|
||||
--? print('text.draw:', f, 'at', line_index,pos, 'after', x,y)
|
||||
if pos < startpos then
|
||||
-- render nothing
|
||||
--? print('skipping', f.data)
|
||||
--? print('skipping', f)
|
||||
else
|
||||
-- render fragment
|
||||
local frag_width = App.width(f.data)
|
||||
local frag_width = App.width(f)
|
||||
if x + frag_width > State.right then
|
||||
assert(x > State.left) -- no overfull lines
|
||||
y = y + State.line_height
|
||||
|
@ -36,7 +36,7 @@ function Text.draw(State, line_index, y, startpos)
|
|||
local lo, hi = Text.clip_selection(State, line_index, pos, pos+frag_len)
|
||||
Text.draw_highlight(State, line, x,y, pos, lo,hi)
|
||||
end
|
||||
App.screen.print(f.data, x,y)
|
||||
App.screen.print(f, x,y)
|
||||
-- render cursor if necessary
|
||||
if line_index == State.cursor1.line then
|
||||
if pos <= State.cursor1.pos and pos + frag_len > State.cursor1.pos then
|
||||
|
@ -47,7 +47,7 @@ function Text.draw(State, line_index, y, startpos)
|
|||
love.graphics.print(State.search_term, x+lo_px,y)
|
||||
end
|
||||
else
|
||||
Text.draw_cursor(State, x+Text.x(f.data, State.cursor1.pos-pos+1), y)
|
||||
Text.draw_cursor(State, x+Text.x(f, State.cursor1.pos-pos+1), y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -88,13 +88,13 @@ function Text.populate_screen_line_starting_pos(State, line_index)
|
|||
local pos = 1
|
||||
for _, f in ipairs(line_cache.fragments) do
|
||||
-- render fragment
|
||||
local frag_width = App.width(f.data)
|
||||
local frag_width = App.width(f)
|
||||
if x + frag_width > State.right then
|
||||
x = State.left
|
||||
table.insert(line_cache.screen_line_starting_pos, pos)
|
||||
end
|
||||
x = x + frag_width
|
||||
pos = pos + utf8.len(f.data)
|
||||
pos = pos + utf8.len(f)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,14 +120,14 @@ function Text.compute_fragments(State, line_index)
|
|||
local frag1 = string.sub(frag, 1, boffset-1)
|
||||
local frag1_width = App.width(frag1)
|
||||
assert(x + frag1_width <= State.right)
|
||||
table.insert(line_cache.fragments, {data=frag1})
|
||||
table.insert(line_cache.fragments, frag1)
|
||||
frag = string.sub(frag, boffset)
|
||||
frag_width = App.width(frag)
|
||||
end
|
||||
x = State.left -- new line
|
||||
end
|
||||
if #frag > 0 then
|
||||
table.insert(line_cache.fragments, {data=frag})
|
||||
table.insert(line_cache.fragments, frag)
|
||||
end
|
||||
x = x + frag_width
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue