bug: delete.wipe = true doesn't affect background buffer in float mode #304

Closed
opened 2026-04-06 04:10:29 +00:00 by llakala · 3 comments
llakala commented 2026-04-06 04:10:29 +00:00

Prerequisites

Neovim version

NVIM v0.12.0
Build type: Release
LuaJIT 2.1.1741730670
Run "nvim -V1 -v" for more info

Operating system

NixOS Unstable

Description

When in a floating window with vim.g.canola.delete = "wipe", deleting the buffer that's currently being edited doesn't affect the buffer in the background. I've actually handled a similar thing before with fzf-lua, to allow deleting the current buffer in the picker. Here's the code for some inspiration:

-- Return a list of the open bufnrs, sorted by how recently they were accessed
local function get_sorted_buflist()
  local info = vim.fn.getbufinfo({ buflisted = 1, bufloaded = 1 })

  -- Take the full info and turn it into just the bufnrs
  local bufnrs = {}
  for index, current in ipairs(info) do
    bufnrs[index] = current.bufnr
  end

  return bufnrs
end

-- Custom action that allows deleting the current buffer. If you do, it swaps to
-- the last buffer you used!
local function delete_buffer_action(selected, opts)
  for _, sel in ipairs(selected) do
    local file = path.entry_to_file(sel, opts)
    local buf_to_delete = file.bufnr

    -- If the current file has unsaved changes, prompt the user to save
    local is_dirty = utils.buffer_is_dirty(buf_to_delete, true, false)
    local save_dialog = function()
      return utils.save_dialog(buf_to_delete)
    end

    if buf_to_delete and (not is_dirty or vim.api.nvim_buf_call(buf_to_delete, save_dialog)) then
      local sorted_buflist = get_sorted_buflist()
      local current_buf = sorted_buflist[1]

      if buf_to_delete == current_buf then
        local windows = vim.fn.win_findbuf(current_buf)

        -- We need the buffer we accessed most recently after the current buf.
        -- We can't use alternate file here, because the REAL current buf is
        -- actually the picker - so we need to go two files back.
        local new_buf = sorted_buflist[2]

        for _, win in ipairs(windows) do
          vim.api.nvim_win_set_buf(win, new_buf)
        end
      end

      vim.api.nvim_buf_delete(buf_to_delete, { force = true })
    end
  end
end

Minimal reproduction

Can reproduce with this config:

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
require("lazy").setup({
  spec = {
    {
      "barrettruth/canola.nvim",
      branch = "canola",
      init = function()
        vim.g.canola = {
          delete = {
            wipe = true,
          },
        }
      end,
    },
  },
})
### Prerequisites - [x] I have searched [existing issues](https://github.com/barrettruth/canola.nvim/issues) - [x] I have updated to the latest version ### Neovim version ```text NVIM v0.12.0 Build type: Release LuaJIT 2.1.1741730670 Run "nvim -V1 -v" for more info ``` ### Operating system NixOS Unstable ### Description When in a floating window with `vim.g.canola.delete = "wipe"`, deleting the buffer that's currently being edited doesn't affect the buffer in the background. I've actually handled a similar thing before with fzf-lua, to allow deleting the current buffer in the picker. Here's the code for some inspiration: ```lua -- Return a list of the open bufnrs, sorted by how recently they were accessed local function get_sorted_buflist() local info = vim.fn.getbufinfo({ buflisted = 1, bufloaded = 1 }) -- Take the full info and turn it into just the bufnrs local bufnrs = {} for index, current in ipairs(info) do bufnrs[index] = current.bufnr end return bufnrs end -- Custom action that allows deleting the current buffer. If you do, it swaps to -- the last buffer you used! local function delete_buffer_action(selected, opts) for _, sel in ipairs(selected) do local file = path.entry_to_file(sel, opts) local buf_to_delete = file.bufnr -- If the current file has unsaved changes, prompt the user to save local is_dirty = utils.buffer_is_dirty(buf_to_delete, true, false) local save_dialog = function() return utils.save_dialog(buf_to_delete) end if buf_to_delete and (not is_dirty or vim.api.nvim_buf_call(buf_to_delete, save_dialog)) then local sorted_buflist = get_sorted_buflist() local current_buf = sorted_buflist[1] if buf_to_delete == current_buf then local windows = vim.fn.win_findbuf(current_buf) -- We need the buffer we accessed most recently after the current buf. -- We can't use alternate file here, because the REAL current buf is -- actually the picker - so we need to go two files back. local new_buf = sorted_buflist[2] for _, win in ipairs(windows) do vim.api.nvim_win_set_buf(win, new_buf) end end vim.api.nvim_buf_delete(buf_to_delete, { force = true }) end end end ``` ### Minimal reproduction Can reproduce with this config: ```lua vim.env.LAZY_STDPATH = ".repro" load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))() require("lazy").setup({ spec = { { "barrettruth/canola.nvim", branch = "canola", init = function() vim.g.canola = { delete = { wipe = true, }, } end, }, }, }) ```
barrettruth commented 2026-04-06 16:47:43 +00:00

let me know if this worked (did for me)

let me know if this worked (did for me)
llakala commented 2026-04-06 17:24:27 +00:00

Working great, thanks! I'm running out of issues to report, which is a good sign.

Working great, thanks! I'm running out of issues to report, which is a good sign.
barrettruth commented 2026-04-06 18:22:12 +00:00

LFG

LFG
Sign in to join this conversation.
No description provided.