feat(view): ability to centralize view on entering (#1310)
This commit is contained in:
parent
821f050fda
commit
1caca62854
@ -87,6 +87,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
|
|||||||
respect_buf_cwd = false,
|
respect_buf_cwd = false,
|
||||||
view = {
|
view = {
|
||||||
adaptive_size = false,
|
adaptive_size = false,
|
||||||
|
centralize_selection = false,
|
||||||
width = 30,
|
width = 30,
|
||||||
height = 30,
|
height = 30,
|
||||||
hide_root_folder = false,
|
hide_root_folder = false,
|
||||||
|
|||||||
@ -105,6 +105,7 @@ Values may be functions. Warning: this may result in unexpected behaviour.
|
|||||||
respect_buf_cwd = false,
|
respect_buf_cwd = false,
|
||||||
view = {
|
view = {
|
||||||
adaptive_size = false,
|
adaptive_size = false,
|
||||||
|
centralize_selection = false,
|
||||||
width = 30,
|
width = 30,
|
||||||
height = 30,
|
height = 30,
|
||||||
hide_root_folder = false,
|
hide_root_folder = false,
|
||||||
@ -454,6 +455,11 @@ Window / buffer setup.
|
|||||||
Only works when |nvim-tree.view.side| is `left` or `right`.
|
Only works when |nvim-tree.view.side| is `left` or `right`.
|
||||||
Type: `boolean`, Default: `false`
|
Type: `boolean`, Default: `false`
|
||||||
|
|
||||||
|
*nvim-tree.view.centralize_selection*
|
||||||
|
When entering nvim-tree, reposition the view so that the current node is
|
||||||
|
initially centralized, see |zz|.
|
||||||
|
Type: `boolean`, Default: `false`
|
||||||
|
|
||||||
*nvim-tree.view.hide_root_folder*
|
*nvim-tree.view.hide_root_folder*
|
||||||
Hide the path of the current working directory on top of the tree.
|
Hide the path of the current working directory on top of the tree.
|
||||||
Type: `boolean`, Default: `false`
|
Type: `boolean`, Default: `false`
|
||||||
|
|||||||
@ -347,6 +347,18 @@ local function setup_autocommands(opts)
|
|||||||
if opts.reload_on_bufenter and not has_watchers then
|
if opts.reload_on_bufenter and not has_watchers then
|
||||||
create_nvim_tree_autocmd("BufEnter", { pattern = "NvimTree_*", callback = reloaders.reload_explorer })
|
create_nvim_tree_autocmd("BufEnter", { pattern = "NvimTree_*", callback = reloaders.reload_explorer })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if opts.view.centralize_selection then
|
||||||
|
create_nvim_tree_autocmd("BufEnter", {
|
||||||
|
pattern = "NvimTree_*",
|
||||||
|
callback = function()
|
||||||
|
vim.schedule(function()
|
||||||
|
local keys = api.nvim_replace_termcodes("zz", true, false, true)
|
||||||
|
api.nvim_feedkeys(keys, "n", true)
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
||||||
@ -366,6 +378,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||||||
respect_buf_cwd = false,
|
respect_buf_cwd = false,
|
||||||
view = {
|
view = {
|
||||||
adaptive_size = false,
|
adaptive_size = false,
|
||||||
|
centralize_selection = false,
|
||||||
width = 30,
|
width = 30,
|
||||||
height = 30,
|
height = 30,
|
||||||
hide_root_folder = false,
|
hide_root_folder = false,
|
||||||
|
|||||||
@ -6,6 +6,7 @@ local events = require "nvim-tree.events"
|
|||||||
|
|
||||||
M.View = {
|
M.View = {
|
||||||
adaptive_size = false,
|
adaptive_size = false,
|
||||||
|
centralize_selection = false,
|
||||||
tabpages = {},
|
tabpages = {},
|
||||||
cursors = {},
|
cursors = {},
|
||||||
hide_root_folder = false,
|
hide_root_folder = false,
|
||||||
@ -394,6 +395,7 @@ end
|
|||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
local options = opts.view or {}
|
local options = opts.view or {}
|
||||||
M.View.adaptive_size = options.adaptive_size
|
M.View.adaptive_size = options.adaptive_size
|
||||||
|
M.View.centralize_selection = options.centralize_selection
|
||||||
M.View.side = options.side
|
M.View.side = options.side
|
||||||
M.View.width = options.width
|
M.View.width = options.width
|
||||||
M.View.height = options.height
|
M.View.height = options.height
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user