Skip to content

Commit

Permalink
perf: add changedtick check to keep snapshot lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
glepnir committed Aug 30, 2024
1 parent 9f40b26 commit 750ce1f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lua/indentmini/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ local get_sw_value, get_indent_lnum = C.get_sw_value, C.get_indent_lnum

--- @class Context
--- @field snapshot table<integer, Snapshot>
local context = { snapshot = {} }
--- @field changedtick integer
local context = { snapshot = {}, changedtick = INVALID }

--- check text only has space or tab see bench/space_or_tab.lua
--- @param text string
Expand Down Expand Up @@ -201,7 +202,10 @@ local function on_win(_, winid, bufnr, toprow, botrow)
then
return false
end
context = { snapshot = {} }
local changedtick = api.nvim_buf_get_changedtick(bufnr)
if changedtick ~= context.changedtick then
context = { snapshot = {}, changedtick = changedtick }
end
context.is_tab = not vim.bo[bufnr].expandtab
for i = toprow, botrow do
context.snapshot[i + 1] = make_snapshot(i + 1)
Expand Down

0 comments on commit 750ce1f

Please sign in to comment.