feat (file_selector): Add multi select (#971)
* Add multi select * Remove comment
This commit is contained in:
parent
42c1d292cf
commit
9895ce7681
@ -163,6 +163,7 @@ function FileSelector:telescope_ui(handler)
|
|||||||
local conf = require("telescope.config").values
|
local conf = require("telescope.config").values
|
||||||
local actions = require("telescope.actions")
|
local actions = require("telescope.actions")
|
||||||
local action_state = require("telescope.actions.state")
|
local action_state = require("telescope.actions.state")
|
||||||
|
local action_utils = require("telescope.actions.utils")
|
||||||
|
|
||||||
pickers
|
pickers
|
||||||
.new(
|
.new(
|
||||||
@ -176,9 +177,21 @@ function FileSelector:telescope_ui(handler)
|
|||||||
map("i", "<esc>", require("telescope.actions").close)
|
map("i", "<esc>", require("telescope.actions").close)
|
||||||
|
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
actions.close(prompt_bufnr)
|
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||||
|
|
||||||
|
if #picker:get_multi_selection() ~= 0 then
|
||||||
|
local selections = {}
|
||||||
|
|
||||||
|
action_utils.map_selections(prompt_bufnr, function(selection) table.insert(selections, selection[1]) end)
|
||||||
|
|
||||||
|
if #selections > 0 then handler(selections) end
|
||||||
|
else
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
|
|
||||||
handler(selection[1])
|
handler(selection[1])
|
||||||
|
end
|
||||||
|
|
||||||
|
actions.close(prompt_bufnr)
|
||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
@ -202,20 +215,24 @@ end
|
|||||||
|
|
||||||
---@return nil
|
---@return nil
|
||||||
function FileSelector:show_select_ui()
|
function FileSelector:show_select_ui()
|
||||||
local handler = function(filepath)
|
local handler = function(filepaths)
|
||||||
if not filepath then return end
|
if not filepaths then return end
|
||||||
|
-- Convert single filepath to array for unified handling
|
||||||
|
local paths = type(filepaths) == "string" and { filepaths } or filepaths
|
||||||
|
|
||||||
|
for _, filepath in ipairs(paths) do
|
||||||
local uniform_path = Utils.uniform_path(filepath)
|
local uniform_path = Utils.uniform_path(filepath)
|
||||||
if Config.file_selector.provider == "native" then
|
if Config.file_selector.provider == "native" then
|
||||||
-- Native handler filters out already selected files
|
|
||||||
table.insert(self.selected_filepaths, uniform_path)
|
table.insert(self.selected_filepaths, uniform_path)
|
||||||
self:emit("update")
|
|
||||||
else
|
else
|
||||||
if not vim.tbl_contains(self.selected_filepaths, uniform_path) then
|
if not vim.tbl_contains(self.selected_filepaths, uniform_path) then
|
||||||
table.insert(self.selected_filepaths, uniform_path)
|
table.insert(self.selected_filepaths, uniform_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self:emit("update")
|
self:emit("update")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
if Config.file_selector.provider == "native" then
|
if Config.file_selector.provider == "native" then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user