From e5553859cd3887a29fe93ad2eaa8841f2de7382f Mon Sep 17 00:00:00 2001 From: devxpain <170700110+devxpain@users.noreply.github.com> Date: Fri, 22 Nov 2024 14:05:13 +0800 Subject: [PATCH] refactor: revert set_last_win_as_target default and move autocmd - Changed the default value of `set_last_win_as_target` back to `false` to maintain original behavior. - Moved the autocmd for `set_last_win_as_target` to `open-file.lua` for better organization. --- doc/nvim-tree-lua.txt | 4 ++-- lua/nvim-tree.lua | 13 +------------ lua/nvim-tree/actions/node/open-file.lua | 9 +++++++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 4779bd64..916d5553 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -570,7 +570,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua }, actions = { use_system_clipboard = true, - set_last_win_as_target = true, + set_last_win_as_target = false, change_dir = { enable = true, global = false, @@ -1441,7 +1441,7 @@ the target window for `nvim-tree`. When enabled, the last active window will be set as the target for file actions (like opening files), ensuring better window management. When disabled, the default behavior applies. - Type: `boolean`, Default: `true` + Type: `boolean`, Default: `false` *nvim-tree.actions.change_dir* vim |current-directory| behaviour. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 8cf7420e..cf9e87bb 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -232,17 +232,6 @@ local function setup_autocommands(opts) end, }) end - - if opts.actions.set_last_win_as_target then - create_nvim_tree_autocmd("BufLeave", { - callback = function() - local buf_name = vim.api.nvim_buf_get_name(0) - if not string.find(buf_name, "NvimTree_") then - require("nvim-tree.lib").set_target_win() - end - end, - }) - end end local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS @@ -440,7 +429,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, actions = { use_system_clipboard = true, - set_last_win_as_target = true, + set_last_win_as_target = false, change_dir = { enable = true, global = false, diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 1d1fc2ec..2aafc9cc 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -426,6 +426,15 @@ function M.setup(opts) opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper() end M.window_picker = opts.actions.open_file.window_picker + if opts.actions.set_last_win_as_target then + vim.api.nvim_create_autocmd("BufLeave", { + callback = function() + if utils.is_nvim_tree_buf then + lib.set_target_win() + end + end, + }) + end end return M