Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(refile): improve ux by matching files more fuzzily #815

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading