From d21d2881d7511eee5fa1afd49ac7544730300854 Mon Sep 17 00:00:00 2001 From: Matthias Bidlingmeyer Date: Fri, 18 Oct 2024 16:49:56 +0200 Subject: [PATCH] feat(refile): improve ux by matching files more fuzzily --- lua/orgmode/capture/init.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lua/orgmode/capture/init.lua b/lua/orgmode/capture/init.lua index 24c1335ba..f968fb1cd 100644 --- a/lua/orgmode/capture/init.lua +++ b/lua/orgmode/capture/init.lua @@ -408,19 +408,17 @@ end ---@param arg_lead string ---@return string[] function Capture:autocomplete_refile(arg_lead) - local valid_filenames = self:_get_autocompletion_files(true) + local valid_files = self:_get_autocompletion_files(true) - if not arg_lead then - return vim.tbl_keys(valid_filenames) + if not arg_lead or #arg_lead == 0 then + return vim.tbl_keys(valid_files) end - local parts = vim.split(arg_lead, '/', { plain = true }) - local selected_file = valid_filenames[parts[1] .. '/'] + local filename = vim.split(arg_lead, '/', { plain = true })[1] + local selected_file = valid_files[filename .. '/'] if not selected_file then - return vim.tbl_filter(function(file) - return file:match('^' .. vim.pesc(parts[1])) - end, vim.tbl_keys(valid_filenames)) + return vim.fn.matchfuzzy(vim.tbl_keys(valid_files), filename) end local headlines = selected_file:get_opened_unfinished_headlines()