Ramilito / kubectl.nvim

Apache License 2.0
158 stars 4 forks source link

bug: toggling plugin off causes the active buffer in editor to also close #58

Closed idelice closed 1 month ago

idelice commented 2 months ago

When toggling (closing) plugin with whatever keybinding set - in my case <leader>k - will also close my active buffer in the background.

Steps

  1. open something with nvim
  2. navigate to some file
  3. toggle plugin on
  4. toggle plugin off

Expectation When executing step 4, the buffer that i've opened in step 2 shouldn't close alongside plugin

Potential fix Rework the toggling functionality so that it only closes the plugin and not anything else.

Example that i've gotten from gitpad.nvim that does it correcly

function M.close_window(opts)
  local wininfo = vim.fn.getwininfo(gitpad_win_id)

  -- We might have closed the window not via this method so we need to
  -- check if the window id is still valid via `getwininfo`
  if gitpad_win_id == nil or vim.tbl_isempty(wininfo) then
    gitpad_win_id = nil
    return false
  end

  local bufnr = vim.api.nvim_win_get_buf(gitpad_win_id)
  local bufname = vim.api.nvim_buf_get_name(bufnr)

  -- Just ensure that we are closing the correct window
  -- This is just to prevent closing a gitpad project window or gitpad branch window
  if bufname == opts.path then
    vim.api.nvim_win_close(gitpad_win_id, true)
    gitpad_win_id = nil
    return true
  end

  return false
end
Ramilito commented 1 month ago

Nice catch! The problem was us setting the bufhidden property was doing something weird with the current window. Fixed that and I don't seem to have caused any other problems 😅