Skip to content

Commit

Permalink
perf(highlight): Skip redraw over folded lines
Browse files Browse the repository at this point in the history
Fixes: folke#285

Currently on a window update such as `WinScroll` highlight_win is
looping through every line from from `w0` to `w$` to update the
highlights. On large files with very large folded regions these two
lines can be very far apart and highlighting every single line can be
costly even though they are not in view. This update adds a check to
skip over any lines hidden in a fold.
  • Loading branch information
mtrajano committed Jul 26, 2024
1 parent 8f45f35 commit ff377fe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lua/todo-comments/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,14 @@ function M.redraw(buf, first, last)
first = math.max(first - Config.options.highlight.multiline_context, 0)
last = math.min(last + Config.options.highlight.multiline_context, vim.api.nvim_buf_line_count(buf))
local state = M.get_state(buf)
for i = first, last do
state.dirty[i] = true
while first <= last do
-- skip over lines that are hidden under a fold
if vim.fn.foldclosed(first) == -1 then
state.dirty[first] = true
else
first = vim.fn.foldclosedend(first)
end
first = first + 1
end
if not M.timer then
M.timer = vim.defer_fn(M.update, Config.options.highlight.throttle)
Expand Down

0 comments on commit ff377fe

Please sign in to comment.