diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-08-15 16:17:15 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-08-15 16:17:15 -0700 |
commit | 1bd5d74b782c19864c3aaad4a113e8df17a34dce (patch) | |
tree | 3743a830d6ef14a0f84f7318b1762fdfe57180bc | |
parent | 5ac18cef45a95cb678e5cebed3b9129bceb982dd (diff) | |
parent | eba973369e0f94e1f89cb05643d7af51d7822568 (diff) | |
download | view.love-1bd5d74b782c19864c3aaad4a113e8df17a34dce.tar.gz |
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.)
-rw-r--r-- | text.lua | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/text.lua b/text.lua index bbe610a..93d2814 100644 --- a/text.lua +++ b/text.lua @@ -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) |