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,23 +8,26 @@ 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
table.insert(items, { if query == "" or item.title:match(query:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1")) then
formatted = item.title, table.insert(items, {
text = item.title, formatted = item.title,
item = item, text = item.title,
idx = i, item = item,
preview = selector.get_preview_content and (function() idx = i,
local content, filetype = selector.get_preview_content(item.id) preview = selector.get_preview_content and (function()
return { local content, filetype = selector.get_preview_content(item.id)
text = content, return {
ft = filetype, text = content,
} ft = filetype,
end)() or nil, }
}) end)() or nil,
})
end
end end
end end
return items return items