diff --git a/config/nvim/lua/lualine/components/fschauen/searchcount.lua b/config/nvim/lua/lualine/components/fschauen/searchcount.lua index d4bb0b7..3883c6b 100644 --- a/config/nvim/lua/lualine/components/fschauen/searchcount.lua +++ b/config/nvim/lua/lualine/components/fschauen/searchcount.lua @@ -6,22 +6,29 @@ function M:init(options) vim.tbl_extend("keep", options or {}, { maxcount = 999, timeout = 250, + cond = function() return vim.v.hlsearch == 1 end, }) ) end -function M:update_status() - if vim.v.hlsearch == 0 then return "" end +local denominator = function(tbl) + if tbl.total > tbl.maxcount then return "󰛤" end + return string.format("%d", tbl.total) +end - local count = vim.fn.searchcount { +local render = function(tbl) + local status = "?" + if not vim.tbl_isempty(tbl) and vim.v.hlsearch == 1 then + status = string.format("%d/%s", tbl.current, denominator(tbl)) + end + return string.format(" %s", status) +end + +function M:update_status() + return render(vim.fn.searchcount { maxcount = self.options.maxcount, timeout = self.options.timeout, - } - if next(count) == nil then return "" end - - local denominator = count.total > count.maxcount and "󰛤" - or string.format("%d", count.total) - return string.format(" %d/%s", count.current, denominator) + }) end return M