Skip to content

Commit

Permalink
feat(refile): improve ux by matching files more fuzzily
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Bidlingmeyer committed Oct 20, 2024
1 parent 05d6983 commit d21d288
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lua/orgmode/capture/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d21d288

Please sign in to comment.