fix: history selector snacks.nvim live search error (#2870)

This commit is contained in:
Waitzz
2025-12-21 19:34:24 +08:00
committed by GitHub
parent b62b6370fc
commit 483c57013c

View File

@@ -8,10 +8,12 @@ function M.show(selector)
Utils.error("Snacks is not set up. Please install and set up Snacks to use it as a file selector.") Utils.error("Snacks is not set up. Please install and set up Snacks to use it as a file selector.")
return return
end end
local function snacks_finder() local function snacks_finder(opts, ctx)
local query = ctx.filter.search or ""
local items = {} local items = {}
for i, item in ipairs(selector.items) do for i, item in ipairs(selector.items) do
if not vim.list_contains(selector.selected_item_ids, item.id) then if not vim.list_contains(selector.selected_item_ids, item.id) then
if query == "" or item.title:match(query:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1")) then
table.insert(items, { table.insert(items, {
formatted = item.title, formatted = item.title,
text = item.title, text = item.title,
@@ -27,6 +29,7 @@ function M.show(selector)
}) })
end end
end end
end
return items return items
end end