feat: add option to set last active window as target for file actions

- Add new option `set_last_win_as_target` to `opts.actions`
- Update documentation to reflect new option
- Set default value of `set_last_win_as_target` to `true`
This commit is contained in:
devxpain 2024-11-19 09:10:32 +08:00
parent f7c65e11d6
commit d8716196f0
2 changed files with 23 additions and 2 deletions

View File

@ -570,6 +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,
change_dir = {
enable = true,
global = false,
@ -1434,6 +1435,14 @@ function are invoked. When enabled, copied text will be stored in registers
'+' (system), otherwise, it will be stored in '1' and '"'.
Type: `boolean`, Default: `true`
*nvim-tree.actions.set_last_win_as_target*
A boolean value that toggles the behavior of setting the last active window as
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`
*nvim-tree.actions.change_dir*
vim |current-directory| behaviour.
@ -2887,6 +2896,7 @@ highlight group is not, hard linking as follows: >
|nvim-tree.actions.open_file.window_picker.picker|
|nvim-tree.actions.remove_file.close_window|
|nvim-tree.actions.use_system_clipboard|
|nvim-tree.actions.set_last_win_as_target|
|nvim-tree.auto_reload_on_write|
|nvim-tree.diagnostics.debounce_delay|
|nvim-tree.diagnostics.enable|

View File

@ -232,6 +232,17 @@ 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
@ -429,6 +440,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
actions = {
use_system_clipboard = true,
set_last_win_as_target = true,
change_dir = {
enable = true,
global = false,
@ -490,8 +502,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
default_yes = false,
},
},
experimental = {
},
experimental = {},
log = {
enable = false,
truncate = false,