Skip to content

fix: safely close last tree window #2913

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

Merged
merged 2 commits into from
Sep 14, 2024
Merged

Conversation

kylebeede
Copy link
Contributor

Addresses the feedback raised in #2904 (review).


Description

Fixes Vim:E444: Cannot close last window error when after running :NvimTreeClose

Minimal config

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvt-min/site]])
local package_root = '/tmp/nvt-min/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
    require('packer').startup({
        {
            'wbthomason/packer.nvim',
            'nvim-tree/nvim-tree.lua',
            'nvim-tree/nvim-web-devicons',
        },
        config = {
            package_root = package_root,
            compile_path = install_path .. '/plugin/packer_compiled.lua',
            display = { non_interactive = true },
        },
    })
end
if vim.fn.isdirectory(install_path) == 0 then
    print('Installing nvim-tree and dependencies.')
    vim.fn.system({ 'git', 'clone', '--depth=1', 'https://github.com./wbthomason/packer.nvim', install_path })
end
load_plugins()
require('packer').sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]])
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
    require('nvim-tree').setup({
        view = {
            float = {
                enable = true,
            },
        },
    })
end

Steps to reproduce

  1. nvim .
  2. :NvimTreeOpen
  3. :NvimTreeClose

Current behavior

nvim-tree closes with the following error:

Error executing Lua callback: ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:230: Vim:E444: Cannot close last window
stack traceback:
        [C]: in function 'nvim_win_close'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:230: in function 'close'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:239: in function 'close_this_tab_only'
        ...e/pack/packer/start/nvim-tree.lua/lua/nvim-tree/view.lua:252: in function 'close'
        ...ck/packer/start/nvim-tree.lua/lua/nvim-tree/commands.lua:25: in function <...ck/packer/start/nvim-tree.lua/lua/nvim-tree/commands.lua:24>

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working nicely, many thanks for your contribution!

20240914_163320

@alex-courtis alex-courtis changed the title fix: safely close tree window with pcall and debug logging fix: safely close last tree window Sep 14, 2024
@alex-courtis alex-courtis merged commit bd48816 into nvim-tree:master Sep 14, 2024
6 checks passed
@kylebeede kylebeede deleted the e444-fix branch September 14, 2024 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants