* Simple mock-up of floating nvim-tree window * Passing whole table to nvim_open_win() * Run update-help.sh * Use vim.api alias * Add comment to float options * Added `anchor` to float options * Enabling float window enforces `actions.open_file.quit_on_open` * Added documentation * add view.float.open_win_config, skipping validation * Made nvim-tree window closes when float is enabled * Close nvim-tree window when out of focus * Update help Co-authored-by: Krzysztof Cieśla <krzysztof.marcin.ciesla@cern.ch> Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
1685484738
commit
7323c81bd6
@ -187,12 +187,24 @@ Subsequent calls to setup will replace the previous configuration.
|
||||
number = false,
|
||||
relativenumber = false,
|
||||
signcolumn = "yes",
|
||||
-- @deprecated
|
||||
mappings = {
|
||||
custom_only = false,
|
||||
list = {
|
||||
-- user mappings go here
|
||||
},
|
||||
},
|
||||
float = {
|
||||
enable = false,
|
||||
open_win_config = {
|
||||
relative = "editor",
|
||||
border = "rounded",
|
||||
width = 30,
|
||||
height = 30,
|
||||
row = 1,
|
||||
col = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
renderer = {
|
||||
add_trailing = false,
|
||||
@ -639,6 +651,25 @@ Window / buffer setup.
|
||||
Type: `table`
|
||||
Default: see |nvim-tree-default-mappings|
|
||||
|
||||
*nvim-tree.view.float*
|
||||
Configuration options for floating window
|
||||
|
||||
*nvim-tree.view.float.enable*
|
||||
Display nvim-tree window as float (enforces |nvim-tree.actions.open_file.quit_on_open| if set).
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
*nvim-tree.view.float.open_win_config*
|
||||
Floating window config. See |nvim_open_win| for more details.
|
||||
Type: `table`, Default:
|
||||
`{`
|
||||
`relative = "editor",`
|
||||
`border = "rounded",`
|
||||
`width = 30,`
|
||||
`height = 30,`
|
||||
`row = 1,`
|
||||
`col = 1,`
|
||||
`}`
|
||||
|
||||
*nvim-tree.renderer*
|
||||
UI rendering setup
|
||||
|
||||
|
||||
@ -414,6 +414,10 @@ local function setup_autocommands(opts)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if opts.view.float.enable then
|
||||
create_nvim_tree_autocmd("WinLeave", { pattern = "NvimTree_*", callback = view.close })
|
||||
end
|
||||
end
|
||||
|
||||
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
@ -453,6 +457,17 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||
-- user mappings go here
|
||||
},
|
||||
},
|
||||
float = {
|
||||
enable = false,
|
||||
open_win_config = {
|
||||
relative = "editor",
|
||||
border = "rounded",
|
||||
width = 30,
|
||||
height = 30,
|
||||
row = 1,
|
||||
col = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
renderer = {
|
||||
add_trailing = false,
|
||||
@ -605,6 +620,10 @@ local function merge_options(conf)
|
||||
return vim.tbl_deep_extend("force", DEFAULT_OPTS, conf or {})
|
||||
end
|
||||
|
||||
local FIELD_SKIP_VALIDATE = {
|
||||
open_win_config = true,
|
||||
}
|
||||
|
||||
local FIELD_OVERRIDE_TYPECHECK = {
|
||||
width = { string = true, ["function"] = true, number = true },
|
||||
height = { string = true, ["function"] = true, number = true },
|
||||
@ -622,25 +641,27 @@ local function validate_options(conf)
|
||||
end
|
||||
|
||||
for k, v in pairs(user) do
|
||||
local invalid
|
||||
local override_typecheck = FIELD_OVERRIDE_TYPECHECK[k] or {}
|
||||
if def[k] == nil then
|
||||
-- option does not exist
|
||||
invalid = string.format("unknown option: %s%s", prefix, k)
|
||||
elseif type(v) ~= type(def[k]) and not override_typecheck[type(v)] then
|
||||
-- option is of the wrong type and is not a function
|
||||
invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v))
|
||||
end
|
||||
|
||||
if invalid then
|
||||
if msg then
|
||||
msg = string.format("%s | %s", msg, invalid)
|
||||
else
|
||||
msg = string.format("%s", invalid)
|
||||
if not FIELD_SKIP_VALIDATE[k] then
|
||||
local invalid
|
||||
local override_typecheck = FIELD_OVERRIDE_TYPECHECK[k] or {}
|
||||
if def[k] == nil then
|
||||
-- option does not exist
|
||||
invalid = string.format("unknown option: %s%s", prefix, k)
|
||||
elseif type(v) ~= type(def[k]) and not override_typecheck[type(v)] then
|
||||
-- option is of the wrong type and is not a function
|
||||
invalid = string.format("invalid option: %s%s expected: %s actual: %s", prefix, k, type(def[k]), type(v))
|
||||
end
|
||||
|
||||
if invalid then
|
||||
if msg then
|
||||
msg = string.format("%s | %s", msg, invalid)
|
||||
else
|
||||
msg = string.format("%s", invalid)
|
||||
end
|
||||
user[k] = nil
|
||||
else
|
||||
validate(v, def[k], prefix .. k .. ".")
|
||||
end
|
||||
user[k] = nil
|
||||
else
|
||||
validate(v, def[k], prefix .. k .. ".")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -280,7 +280,7 @@ function M.fn(mode, filename)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.quit_on_open = opts.actions.open_file.quit_on_open
|
||||
M.quit_on_open = opts.actions.open_file.quit_on_open or opts.view.float.enable
|
||||
M.resize_window = opts.actions.open_file.resize_window
|
||||
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()
|
||||
|
||||
@ -134,8 +134,12 @@ local function set_window_options_and_buffer()
|
||||
end
|
||||
|
||||
local function open_window()
|
||||
a.nvim_command "vsp"
|
||||
M.reposition_window()
|
||||
if M.View.float.enable then
|
||||
a.nvim_open_win(0, true, M.View.float.open_win_config)
|
||||
else
|
||||
a.nvim_command "vsp"
|
||||
M.reposition_window()
|
||||
end
|
||||
setup_tabpage(a.nvim_get_current_tabpage())
|
||||
set_window_options_and_buffer()
|
||||
end
|
||||
@ -431,6 +435,7 @@ function M.setup(opts)
|
||||
M.View.winopts.number = options.number
|
||||
M.View.winopts.relativenumber = options.relativenumber
|
||||
M.View.winopts.signcolumn = options.signcolumn
|
||||
M.View.float = options.float
|
||||
M.on_attach = opts.on_attach
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user