Skip to content
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