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

Don't Close Window On fs.remove() When Last Buffer In Window #2861

Open
siduck opened this issue Aug 3, 2024 · 5 comments
Open

Don't Close Window On fs.remove() When Last Buffer In Window #2861

siduck opened this issue Aug 3, 2024 · 5 comments

Comments

@siduck
Copy link
Contributor

siduck commented Aug 3, 2024

Problem
When there's just 1 window opened along with nvimtree, then deleting its file from tree, would make nvimtree become fullscreen

Desired behavior
Nvimtree should open unamed buf ( enew ) and then delete, this will maintain the win layout!

 actions = {
    remove_file = {
      open_unamed_buf = true,
    },
  },

Possible solutions with edgecases

The code must be run only when the user presses "y"

Case 1

If there's just 1 listed buffer and its the active window

  • Add empty buffer i.e enew
  • delete
@alex-courtis
Copy link
Member

Discussions: NvChad/NvChad#2950

TL;DR: this is possible but will be tricky from a functional and technical perspective.

@alex-courtis alex-courtis changed the title Prevent Nvim-tree window from becoming full-screen on deleting active buffer file Don't Close Window On fs.remove() When Last Buffer In Window Aug 3, 2024
@siduck
Copy link
Contributor Author

siduck commented Aug 3, 2024

image

cant we create an unnamed buf and place it in the window of the buffer which is getting deleted 🤔

@alex-courtis
Copy link
Member

cant we create an unnamed buf and place it in the window of the buffer which is getting deleted 🤔

That sounds sensible.

@siduck
Copy link
Contributor Author

siduck commented Aug 3, 2024

so would this be added to nvimtree or the user has to add in his config? I tried with an autocmd

vim.api.nvim_create_autocmd("BufDelete", {
  callback = function()
    local cur_buf = vim.api.nvim_get_current_buf()
    local cur_ft = vim.bo[cur_buf].ft

    if cur_ft == "NvimTree" and #vim.fn.getbufinfo { buflisted = 1 } == 1 then
      vim.cmd "bn"
      vim.cmd "enew"
    end
  end,
})

but this closes nvimtree window too, no idea why

@alex-courtis alex-courtis reopened this Aug 3, 2024
@alex-courtis
Copy link
Member

This is something that should go into nvim-tree itself. It needs the internals of remove-file.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants