Skip to content

Commit

Permalink
fix: use pcall for search count
Browse files Browse the repository at this point in the history
search with \_ make it broken
  • Loading branch information
zztrieuzz committed Oct 22, 2022
1 parent c743248 commit be7184c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lua/windline/components/vim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ M.cmdl_search_leave = function()
-- need to wait cmd finish search to get last search pattern
vim.defer_fn(function()
local pattern = vim.fn.getreg('/')
vim.fn.searchcount({ pattern = pattern })
pcall(vim.fn.searchcount, { pattern = pattern })
end, 10)
end

Expand All @@ -14,7 +14,7 @@ M.cmdl_search_enter = function()
if vim.v.hlsearch == 1 and vim.api.nvim_win_get_config(0).relative == '' then
local pattern = vim.fn.getreg('/')
if pattern and #pattern > 1 then
vim.fn.searchcount({ pattern = pattern })
pcall(vim.fn.searchcount, { pattern = pattern })
end
end
end
Expand Down Expand Up @@ -49,8 +49,9 @@ M.search_count = function(opt)
if vim.v.hlsearch == 0 then
return ''
end
local result = vim.fn.searchcount({ recompute = 0 })
if not result or result.current == nil then

local check, result = pcall(vim.fn.searchcount, { recompute = 0 })
if not check or not result or result.current == nil then
return ''
end

Expand Down

0 comments on commit be7184c

Please sign in to comment.