* 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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user