feat: add maxcount & timeout options to searchcount (#958)

This commit is contained in:
Myshko Dm 2023-03-30 08:30:15 +03:00 committed by GitHub
parent 267dba7d37
commit 2ee2fd5b2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 3 deletions

View File

@ -655,6 +655,20 @@ sections = {
}
```
#### searchcount component options
```lua
sections = {
lualine_a = {
{
'searchcount',
maxcount = 999,
timeout = 500,
}
}
}
```
#### tabs component options
```lua

View File

@ -1,11 +1,27 @@
local function searchcount()
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 = 999, timeout = 500 }
local result = vim.fn.searchcount { maxcount = self.options.maxcount, timeout = self.options.timeout }
local denominator = math.min(result.total, result.maxcount)
return string.format('[%d/%d]', result.current, denominator)
end
return searchcount
return M