summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorTheMeaningfulEngineer <alan.martinovic@gmail.com>2022-05-29 19:54:31 +0200
committerSimon Hauser <simon.hauser@helsinki-systems.de>2022-06-30 14:01:50 +0200
commita6c9ae088e354c529db8bedf04166e1ab8a6f1b2 (patch)
tree75eb5edfa7ff5e2192cf7a899d0b761fc13eea39 /lua
parent6dc0a7d7c26d6620043cabf1dca3619fee6d3c62 (diff)
feat: force buffer delete for terminal and improvements for Picker:delete_selection (#1943)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/actions/init.lua4
-rw-r--r--lua/telescope/pickers.lua8
2 files changed, 8 insertions, 4 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua
index 0413f33..0382014 100644
--- a/lua/telescope/actions/init.lua
+++ b/lua/telescope/actions/init.lua
@@ -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
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua
index 4cc1623..9397c57 100644
--- a/lua/telescope/pickers.lua
+++ b/lua/telescope/pickers.lua
@@ -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