From 750ce1fbbabdb3eed666d38b4f00dc857322772f Mon Sep 17 00:00:00 2001 From: glepnir Date: Fri, 30 Aug 2024 18:48:08 +0800 Subject: [PATCH] perf: add changedtick check to keep snapshot lifetime --- lua/indentmini/init.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lua/indentmini/init.lua b/lua/indentmini/init.lua index 1297b60..7ab90ff 100644 --- a/lua/indentmini/init.lua +++ b/lua/indentmini/init.lua @@ -36,7 +36,8 @@ local get_sw_value, get_indent_lnum = C.get_sw_value, C.get_indent_lnum --- @class Context --- @field snapshot table -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 @@ -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)