nvim-neo-tree / neo-tree.nvim

Neovim plugin to manage the file system and other tree like structures.
MIT License
3.8k stars 220 forks source link

BUG: close_all() function in event handler does not work when opening in new tab #1442

Open sergiopatino opened 6 months ago

sergiopatino commented 6 months ago

Did you check docs and existing issues?

Neovim Version (nvim -v)

NVIM v0.10.0-dev

Operating System / Version

MacOs 14.4.1 (23E224)

Describe the Bug

The following even handler provided in the documentation does not work when opening a file in a new tab.

        event_handlers = {
            -- Close neo-tree when opening a file.
            {
                event = 'file_opened',
                handler = function()
                    require('neo-tree').close_all()
                end,
            },
        },

The neo-tree window remains open in the previous tab the file was opened from. Should this be expected to close the neo-tree window even though it's in the previous tab? Is there a way to accomplish this functionality currently?

Screenshots, Traceback

No response

Steps to Reproduce

  1. open Neovim
  2. Open neo-tree
  3. open file in current tab
  4. open another file in neo-tree but in a new tab.
  5. go back to the previous tab. neo-tree is still open.

Expected Behavior

It should close the neo-tree window even when opening a file in a new tab.

Your Configuration

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  -- add any other plugins here
}

local neotree_config = {
  "nvim-neo-tree/neo-tree.nvim",
  dependencies = { "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" },
  cmd = { "Neotree" },
  keys = {
    { "<Leader>e", "<Cmd>Neotree<CR>" }, -- change or remove this line if relevant.
  },
  opts = {
    -- Your config here
    -- ...
  },
}

table.insert(plugins, neotree_config)
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
cseickel commented 6 months ago

If you want Neo-tree to close after you open a file, then you really shouldn't be using a sidebar position. The float position would probably be the most appropriate for how you are using it.