diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2022-08-17 16:15:35 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2022-08-17 16:15:35 -0700 |
commit | 1221fde164c47480f3c30209ad5167e4a005769a (patch) | |
tree | b1cac785d137e6520b87e9a9c4108dbd0b81fa21 | |
parent | 3a74e4bb6cb350efa395e9d7189180e1cfc49af9 (diff) | |
download | view.love-1221fde164c47480f3c30209ad5167e4a005769a.tar.gz |
move caching behavior inside compute_fragments
-rw-r--r-- | text.lua | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/text.lua b/text.lua index fb85d63..c38dc1e 100644 --- a/text.lua +++ b/text.lua @@ -18,9 +18,7 @@ function Text.draw(State, line_index, y, startpos) local x = State.left local pos = 1 local screen_line_starting_pos = startpos - if line_cache.fragments == nil then - Text.compute_fragments(State, line_index) - end + Text.compute_fragments(State, line_index) for _, f in ipairs(line_cache.fragments) do local frag, frag_text = f.data, f.text local frag_len = utf8.len(frag) @@ -90,9 +88,7 @@ function Text.populate_screen_line_starting_pos(State, line_index) return end -- duplicate some logic from Text.draw - if line_cache.fragments == nil then - Text.compute_fragments(State, line_index) - end + Text.compute_fragments(State, line_index) line_cache.screen_line_starting_pos = {1} local x = State.left local pos = 1 @@ -113,7 +109,11 @@ end function Text.compute_fragments(State, line_index) --? print('compute_fragments', line_index, 'between', State.left, State.right) local line = State.lines[line_index] + if line.mode ~= 'text' then return end local line_cache = State.line_cache[line_index] + if line_cache.fragments then + return + end line_cache.fragments = {} local x = State.left -- try to wrap at word boundaries |