From 348beb3ab27f07b0bbb9fa63f5c0c080388a9f52 Mon Sep 17 00:00:00 2001 From: wongxy Date: Fri, 15 Apr 2022 12:34:45 +0800 Subject: [PATCH] improve: use a shorter delay when the total lines is changed --- plugin/virt-column.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugin/virt-column.lua b/plugin/virt-column.lua index db4d33d..2b572c4 100644 --- a/plugin/virt-column.lua +++ b/plugin/virt-column.lua @@ -106,7 +106,15 @@ local function refresh(args) textchanged_timer:stop() textchanged_timer:close() end - textchanged_timer = vim.defer_fn(_refresh, 500) + local lines_count = vim.fn.line "$" + local delay + if lines_count ~= vim.b.virtcolumn_lines_count then + vim.b.virtcolumn_lines_count = lines_count + delay = 50 + else + delay = 500 + end + textchanged_timer = vim.defer_fn(_refresh, delay) else _refresh() end