fix: add config for preserving window proportions on open file (#999)

This commit is contained in:
Richard Mathieson
2022-02-23 00:04:14 +11:00
committed by GitHub
parent 61b57e3676
commit 3486c48225
4 changed files with 20 additions and 7 deletions

View File

@@ -151,6 +151,7 @@ require'nvim-tree'.setup {
hide_root_folder = false, hide_root_folder = false,
side = 'left', side = 'left',
auto_resize = false, auto_resize = false,
preserve_window_proportions = false,
mappings = { mappings = {
custom_only = false, custom_only = false,
list = {} list = {}

View File

@@ -113,6 +113,7 @@ function.
height = 30, height = 30,
side = 'left', side = 'left',
auto_resize = false, auto_resize = false,
preserve_window_proportions = false,
number = false, number = false,
relativenumber = false, relativenumber = false,
signcolumn = "yes", signcolumn = "yes",
@@ -332,17 +333,23 @@ Here is a list of the options available in the setup call:
- |view.auto_resize|: auto resize the tree after opening a file - |view.auto_resize|: auto resize the tree after opening a file
type: `boolean` type: `boolean`
default: false default: `false`
- |view.preserve_window_proportions|: preserve window proportions when
opening a file. If `false`, the height and width of windows other than
nvim-tree will be equalized.
type: `boolean`
default: `false`
- |view.number|: print the line number in front of each line. - |view.number|: print the line number in front of each line.
type: `boolean` type: `boolean`
default: false default: `false`
- |view.relativenumber|: show the line number relative to the line with the - |view.relativenumber|: show the line number relative to the line with the
cursor in front of each line. If the option `view.number` is also `true`, cursor in front of each line. If the option `view.number` is also `true`,
the number on the cursor line will be the line number instead of `0`. the number on the cursor line will be the line number instead of `0`.
type: `boolean` type: `boolean`
default: false default: `false`
- |view.signcolumn|: show diagnostic sign column. Value can be `"yes"`, - |view.signcolumn|: show diagnostic sign column. Value can be `"yes"`,
`"auto"`, `"no"` `"auto"`, `"no"`
@@ -354,11 +361,11 @@ Here is a list of the options available in the setup call:
- |view.mappings.custom_only|: will use only the provided user mappings and not the default - |view.mappings.custom_only|: will use only the provided user mappings and not the default
otherwise, extends the default mappings with the provided user mappings otherwise, extends the default mappings with the provided user mappings
type: `boolean` type: `boolean`
default: false default: `false`
- |view.mappings.list|: a list of keymaps that will extend or override the default keymaps - |view.mappings.list|: a list of keymaps that will extend or override the default keymaps
type: list of `{ key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }` type: list of `{ key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }`
default: {} default: `{}`
*nvim-tree.filters* *nvim-tree.filters*
|filters|: filtering options |filters|: filtering options

View File

@@ -368,7 +368,7 @@ local DEFAULT_OPTS = {
exclude = vim.g.nvim_tree_window_picker_exclude, exclude = vim.g.nvim_tree_window_picker_exclude,
} }
} }
} },
} }
local function merge_options(conf) local function merge_options(conf)

View File

@@ -179,7 +179,10 @@ function M.resize(size)
else else
a.nvim_win_set_height(M.get_winnr(), get_size()) a.nvim_win_set_height(M.get_winnr(), get_size())
end end
vim.cmd ":wincmd ="
if not M.View.preserve_window_proportions then
vim.cmd(":wincmd =")
end
end end
function M.reposition_window() function M.reposition_window()
@@ -321,6 +324,7 @@ local DEFAULT_CONFIG = {
height = 30, height = 30,
side = 'left', side = 'left',
auto_resize = false, auto_resize = false,
preserve_window_proportions = false,
number = false, number = false,
relativenumber = false, relativenumber = false,
signcolumn = 'yes' signcolumn = 'yes'
@@ -333,6 +337,7 @@ function M.setup(opts)
M.View.height = options.height M.View.height = options.height
M.View.hide_root_folder = options.hide_root_folder M.View.hide_root_folder = options.hide_root_folder
M.View.auto_resize = options.auto_resize M.View.auto_resize = options.auto_resize
M.View.preserve_window_proportions = options.preserve_window_proportions
M.View.winopts.number = options.number M.View.winopts.number = options.number
M.View.winopts.relativenumber = options.relativenumber M.View.winopts.relativenumber = options.relativenumber
M.View.winopts.signcolumn = options.signcolumn M.View.winopts.signcolumn = options.signcolumn