9f496ce
dotfiles.git > main > 9f496ce > files
Improve fuzzy file search for the sake of markdown files
Commit: 9f496ceb3308ba25f1a5bb7a745ca07f749ff056
Parent: 5dec7c2
1 changed file:
nvim/lua/picker.lua view file
@@ -29,16 +29,22 @@ vim.wo[list_win].cursorline = true api.nvim_set_current_win(prompt_win) - local p = {items = items, query = "", matches = {}}+ local p = {query = "", matches = {}} local done = false + local function set(new)+ p.items = new+ p.keyed = vim.tbl_map(function(s) return {k = s:lower(), s = s} end, new)+ end+ set(items)+ local function query() return api.nvim_buf_get_lines(prompt_buf, 0, 1, false)[1] end local function refilter() p.query = query()- local res = p.query == "" and {vim.list_slice(p.items, 1, h), {}}- or fn.matchfuzzypos(p.items, p.query, {limit = h})- p.matches = res[1]+ local res = p.query == "" and {p.items, {}} or fn.matchfuzzypos(p.keyed, p.query:lower(), {key = "k"})+ p.matches = vim.tbl_map(function(m) return type(m) == "table" and m.s or m end, vim.list_slice(res[1], 1, h))+ res[2] = vim.list_slice(res[2], 1, h) local lines = {} for row = 1, h do lines[row] = p.matches[h - row + 1] or "" end api.nvim_buf_set_lines(list_buf, 0, -1, false, lines)@@ -91,7 +97,7 @@ api.nvim_create_autocmd("WinLeave", {buffer = prompt_buf, callback = function() close() end}) function p.set_items(new)- if not done then p.items = new; refilter() end+ if not done then set(new); refilter() end end refilter()