Skip to content

Commit e555385

Browse files
committed
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.
1 parent d871619 commit e555385

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

doc/nvim-tree-lua.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ Following is the default configuration. See |nvim-tree-opts| for details. >lua
570570
},
571571
actions = {
572572
use_system_clipboard = true,
573-
set_last_win_as_target = true,
573+
set_last_win_as_target = false,
574574
change_dir = {
575575
enable = true,
576576
global = false,
@@ -1441,7 +1441,7 @@ the target window for `nvim-tree`. When enabled, the last active window will be
14411441
set as the target for file actions (like opening files), ensuring better window
14421442
management. When disabled, the default behavior applies.
14431443

1444-
Type: `boolean`, Default: `true`
1444+
Type: `boolean`, Default: `false`
14451445

14461446
*nvim-tree.actions.change_dir*
14471447
vim |current-directory| behaviour.

lua/nvim-tree.lua

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,6 @@ local function setup_autocommands(opts)
232232
end,
233233
})
234234
end
235-
236-
if opts.actions.set_last_win_as_target then
237-
create_nvim_tree_autocmd("BufLeave", {
238-
callback = function()
239-
local buf_name = vim.api.nvim_buf_get_name(0)
240-
if not string.find(buf_name, "NvimTree_") then
241-
require("nvim-tree.lib").set_target_win()
242-
end
243-
end,
244-
})
245-
end
246235
end
247236

248237
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
@@ -440,7 +429,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
440429
},
441430
actions = {
442431
use_system_clipboard = true,
443-
set_last_win_as_target = true,
432+
set_last_win_as_target = false,
444433
change_dir = {
445434
enable = true,
446435
global = false,

lua/nvim-tree/actions/node/open-file.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,15 @@ function M.setup(opts)
426426
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()
427427
end
428428
M.window_picker = opts.actions.open_file.window_picker
429+
if opts.actions.set_last_win_as_target then
430+
vim.api.nvim_create_autocmd("BufLeave", {
431+
callback = function()
432+
if utils.is_nvim_tree_buf then
433+
lib.set_target_win()
434+
end
435+
end,
436+
})
437+
end
429438
end
430439

431440
return M

0 commit comments

Comments
 (0)