NvChad / ui

Lightweight & high performance UI plugin for nvchad
GNU General Public License v3.0
208 stars 124 forks source link

When trying to close a buffer while the current buffer is terminal the terminal closes instead of that buffer #319

Closed adamallaf closed 2 months ago

adamallaf commented 2 months ago

When trying to close a buffer while the current buffer is terminal the terminal closes instead of that buffer.

Steps to reproduce:

  1. open nvim (with nvchad ui)
  2. open any buffer (;e abc)
  3. split window (ctrl + w, s)
  4. open terminal (;term)
  5. while the terminal is the current buffer click the X on any other buffer

Expected result:

The closed buffer should close.

Actual result:

Current terminal buffer is closed instead of the closed buffer.

The issue is probably caused by checking if buffer's type is terminal in this line: https://github.com/NvChad/ui/blob/v2.5/lua/nvchad/tabufline/init.lua#L39

Checking if current buffer is the same as bufnr in close function should fix that.

And this is the fix I would like to suggest: https://github.com/NvChad/ui/commit/87faf6e5e83d031f1f79cf6a6e336f95d83e40e5

commit 459e44d55f3f391febe73df2a3a6047fee7bfd36
Author: Adam Allaf <adam.allaf@hotmail.com>
Date:   Sat Jul 20 08:14:31 2024 +0200

    Fix for current terminal buffer closing when closing other buffer

diff --git a/lua/nvchad/tabufline/init.lua b/lua/nvchad/tabufline/init.lua
index 105da44..69f670e 100644
--- a/lua/nvchad/tabufline/init.lua
+++ b/lua/nvchad/tabufline/init.lua
@@ -36,7 +36,7 @@ M.prev = function()
 end

 M.close_buffer = function(bufnr)
-  if vim.bo.buftype == "terminal" then
+  if vim.bo.buftype == "terminal" and cur_buf() == bufnr then
     vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide")
   else
     -- for those who have disabled tabufline