feat(view): add float.quit_on_focus_loss, float respects actions.open_file.quit_on_open (#1621)

This commit is contained in:
emmanueltouzery 2022-10-08 05:35:20 +02:00 committed by GitHub
parent be2b4f58e6
commit 79f631bc1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 4 deletions

View File

@ -702,9 +702,13 @@ Window / buffer setup.
Configuration options for floating window Configuration options for floating window
*nvim-tree.view.float.enable* *nvim-tree.view.float.enable*
Display nvim-tree window as float (enforces |nvim-tree.actions.open_file.quit_on_open| if set). Display nvim-tree window as float (enforces if set).
Type: `boolean`, Default: `false` Type: `boolean`, Default: `false`
*nvim-tree.view.float.quit_on_focus_loss
When in floating mode, autoclose the popup when the popup loses the focus.
Type: `boolean`, Default: `true`
*nvim-tree.view.float.open_win_config* *nvim-tree.view.float.open_win_config*
Floating window config. See |nvim_open_win| for more details. Floating window config. See |nvim_open_win| for more details.
Type: `table` or `function` that returns a table, Default: Type: `table` or `function` that returns a table, Default:

View File

@ -412,7 +412,7 @@ local function setup_autocommands(opts)
}) })
end end
if opts.view.float.enable then if opts.view.float.enable and opts.view.float.quit_on_focus_loss then
create_nvim_tree_autocmd("WinLeave", { pattern = "NvimTree_*", callback = view.close }) create_nvim_tree_autocmd("WinLeave", { pattern = "NvimTree_*", callback = view.close })
end end
end end
@ -457,6 +457,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
}, },
float = { float = {
enable = false, enable = false,
quit_on_focus_loss = true,
open_win_config = { open_win_config = {
relative = "editor", relative = "editor",
border = "rounded", border = "rounded",

View File

@ -267,7 +267,7 @@ function M.fn(mode, filename)
end end
function M.setup(opts) function M.setup(opts)
M.quit_on_open = opts.actions.open_file.quit_on_open or opts.view.float.enable M.quit_on_open = opts.actions.open_file.quit_on_open
M.resize_window = opts.actions.open_file.resize_window M.resize_window = opts.actions.open_file.resize_window
if opts.actions.open_file.window_picker.chars then if opts.actions.open_file.window_picker.chars then
opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper() opts.actions.open_file.window_picker.chars = tostring(opts.actions.open_file.window_picker.chars):upper()

View File

@ -25,7 +25,7 @@ local overlay_bufnr = nil
local overlay_winnr = nil local overlay_winnr = nil
local function remove_overlay() local function remove_overlay()
if view.View.float.enable then if view.View.float.enable and view.View.float.quit_on_focus_loss then
-- return to normal nvim-tree float behaviour when filter window is closed -- return to normal nvim-tree float behaviour when filter window is closed
a.nvim_create_autocmd("WinLeave", { a.nvim_create_autocmd("WinLeave", {
pattern = "NvimTree_*", pattern = "NvimTree_*",