From e2e7720caa0722707bceffcadf25865cdb8e0bc5 Mon Sep 17 00:00:00 2001 From: kiyan Date: Thu, 30 Sep 2021 12:26:55 +0200 Subject: [PATCH] fix: properly hijack netrw, don't always open on dir - fix hijack netrw logic - do not open on directory if open_on_setup is false, but do if the window is open. --- lua/nvim-tree.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index de3675f0..26a3092d 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -19,7 +19,7 @@ local _config = { }, system_open = {}, ignore_ft_on_setup = {}, - open_on_setup = {}, + open_on_setup = false, } local M = {} @@ -301,6 +301,9 @@ function M.on_leave() end function M.open_on_directory() + if not (_config.open_on_setup or view.win_open()) then + return + end local buf = api.nvim_get_current_buf() local bufname = api.nvim_buf_get_name(buf) if vim.fn.isdirectory(bufname) ~= 1 or bufname == lib.Tree.cwd then @@ -343,11 +346,12 @@ function M.place_cursor_on_node() end local function manage_netrw(disable_netrw, hijack_netrw) + if hijack_netrw then + vim.cmd "silent! autocmd! FileExplorer *" + end if disable_netrw then vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 - elseif hijack_netrw then - vim.cmd "silent! autocmd! FileExplorer *" end end