feat: add add_to_qflist, add_selected, and smart_add (#636)

* feat: add `add_to_qflist`, `add_selected`, and `smart_add`

* refactor: use local function
This commit is contained in:
elianiva
2021-03-12 11:00:15 +07:00
committed by GitHub
parent add7ee3943
commit c8cc024ebf

View File

@@ -384,7 +384,7 @@ local entry_to_qf = function(entry)
} }
end end
actions.send_selected_to_qflist = function(prompt_bufnr) local send_selected_to_qf = function(prompt_bufnr, mode)
local picker = action_state.get_current_picker(prompt_bufnr) local picker = action_state.get_current_picker(prompt_bufnr)
local qf_entries = {} local qf_entries = {}
@@ -394,10 +394,10 @@ actions.send_selected_to_qflist = function(prompt_bufnr)
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
vim.fn.setqflist(qf_entries, 'r') vim.fn.setqflist(qf_entries, mode)
end end
actions.send_to_qflist = function(prompt_bufnr) local send_all_to_qf = function(prompt_bufnr, mode)
local picker = action_state.get_current_picker(prompt_bufnr) local picker = action_state.get_current_picker(prompt_bufnr)
local manager = picker.manager local manager = picker.manager
@@ -408,16 +408,40 @@ actions.send_to_qflist = function(prompt_bufnr)
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
vim.fn.setqflist(qf_entries, 'r') vim.fn.setqflist(qf_entries, mode)
end
actions.send_selected_to_qflist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, 'r')
end
actions.add_selected_to_qflist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, 'a')
end
actions.send_to_qflist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, 'r')
end
actions.add_to_qflist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, 'a')
end
local smart_send = function(prompt_bufnr, mode)
local picker = action_state.get_current_picker(prompt_bufnr)
if table.getn(picker:get_multi_selection()) > 0 then
send_selected_to_qf(prompt_bufnr, mode)
else
send_all_to_qf(prompt_bufnr, mode)
end
end end
actions.smart_send_to_qflist = function(prompt_bufnr) actions.smart_send_to_qflist = function(prompt_bufnr)
local picker = action_state.get_current_picker(prompt_bufnr) smart_send(prompt_bufnr, 'r')
if table.getn(picker:get_multi_selection()) > 0 then end
actions.send_selected_to_qflist(prompt_bufnr)
else actions.smart_add_to_qflist = function(prompt_bufnr)
actions.send_to_qflist(prompt_bufnr) smart_send(prompt_bufnr, 'a')
end
end end
actions.complete_tag = function(prompt_bufnr) actions.complete_tag = function(prompt_bufnr)