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.
This commit is contained in:
devxpain 2024-11-22 14:05:13 +08:00
parent d8716196f0
commit e5553859cd
3 changed files with 12 additions and 14 deletions

View File

@ -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.

View File

@ -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,

View File

@ -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