Chris1320 c28a7427c3
Fix: searchcount error (#1004) (#1005)
- `searchcount.lua` now checks if the resulting table from
  `vim.fn.searchcount` is empty to avoid the error.

Signed-off-by: Chris1320 <chris1320is@protonmail.com>
2023-04-03 16:41:41 +06:00

32 lines
737 B
Lua

local M = require('lualine.component'):extend()
local default_options = {
maxcount = 999,
timeout = 500,
}
-- Initializer
function M:init(options)
-- Run super()
M.super.init(self, options)
-- Apply default options
self.options = vim.tbl_extend('keep', self.options or {}, default_options)
end
-- Function that runs every time statusline is updated
function M:update_status()
if vim.v.hlsearch == 0 then
return ''
end
local result = vim.fn.searchcount { maxcount = self.options.maxcount, timeout = self.options.timeout }
if next(result) == nil then
return ''
end
local denominator = math.min(result.total, result.maxcount)
return string.format('[%d/%d]', result.current, denominator)
end
return M