Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force buffer delete for terminal #1943

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion lua/telescope/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions lua/telescope/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,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
Expand All @@ -718,8 +718,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
Expand Down