feat: force buffer delete for terminal and improvements for Picker:delete_selection (#1943)
This commit is contained in:
committed by
Simon Hauser
parent
6dc0a7d7c2
commit
a6c9ae088e
@@ -1020,7 +1020,9 @@ end
|
||||
actions.delete_buffer = function(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
current_picker:delete_selection(function(selection)
|
||||
vim.api.nvim_buf_delete(selection.bufnr, { force = false })
|
||||
local force = vim.api.nvim_buf_get_option(selection.bufnr, "buftype") == "terminal"
|
||||
local ok = pcall(vim.api.nvim_buf_delete, selection.bufnr, { force = force })
|
||||
return ok
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -693,7 +693,7 @@ end
|
||||
---
|
||||
--- Example usage in telescope:
|
||||
--- - `actions.delete_buffer()`
|
||||
---@param delete_cb function: called with each deleted selection
|
||||
---@param delete_cb function: called for each selection fn(s) -> bool|nil (true|nil removes the entry from the results)
|
||||
function Picker:delete_selection(delete_cb)
|
||||
vim.validate { delete_cb = { delete_cb, "f" } }
|
||||
local original_selection_strategy = self.selection_strategy
|
||||
@@ -719,8 +719,10 @@ function Picker:delete_selection(delete_cb)
|
||||
return x > y
|
||||
end)
|
||||
for _, index in ipairs(selection_index) do
|
||||
local selection = table.remove(self.finder.results, index)
|
||||
delete_cb(selection)
|
||||
local delete_cb_return = delete_cb(self.finder.results[index])
|
||||
if delete_cb_return == nil or delete_cb_return == true then
|
||||
table.remove(self.finder.results, index)
|
||||
end
|
||||
end
|
||||
|
||||
if used_multi_select then
|
||||
|
||||
Reference in New Issue
Block a user