Merge lines.love

(I'm going to change the format of these commits to be more useful in
the presence of more than one level of upstream.)
This commit is contained in:
Kartik K. Agaram 2022-08-15 16:17:15 -07:00
commit 1bd5d74b78

View File

@ -82,6 +82,33 @@ function Text.draw_cursor(State, x, y)
State.cursor_y = y+State.line_height
end
function Text.populate_screen_line_starting_pos(State, line_index)
local line = State.lines[line_index]
local line_cache = State.line_cache[line_index]
if line_cache.screen_line_starting_pos then
return
end
-- duplicate some logic from Text.draw
if line_cache.fragments == nil then
Text.compute_fragments(State, line_index)
end
line_cache.screen_line_starting_pos = {1}
local x = State.left
local pos = 1
for _, f in ipairs(line_cache.fragments) do
local frag, frag_text = f.data, f.text
-- render fragment
local frag_width = App.width(frag_text)
if x + frag_width > State.right then
x = State.left
table.insert(line_cache.screen_line_starting_pos, pos)
end
x = x + frag_width
local frag_len = utf8.len(frag)
pos = pos + frag_len
end
end
function Text.compute_fragments(State, line_index)
--? print('compute_fragments', line_index, 'between', State.left, State.right)
local line = State.lines[line_index]
@ -843,33 +870,6 @@ function Text.previous_screen_line(State, loc2)
end
end
function Text.populate_screen_line_starting_pos(State, line_index)
local line = State.lines[line_index]
local line_cache = State.line_cache[line_index]
if line_cache.screen_line_starting_pos then
return
end
-- duplicate some logic from Text.draw
if line_cache.fragments == nil then
Text.compute_fragments(State, line_index)
end
line_cache.screen_line_starting_pos = {1}
local x = State.left
local pos = 1
for _, f in ipairs(line_cache.fragments) do
local frag, frag_text = f.data, f.text
-- render fragment
local frag_width = App.width(frag_text)
if x + frag_width > State.right then
x = State.left
table.insert(line_cache.screen_line_starting_pos, pos)
end
x = x + frag_width
local frag_len = utf8.len(frag)
pos = pos + frag_len
end
end
-- resize helper
function Text.tweak_screen_top_and_cursor(State)
--? print('a', State.selection1.line)