feature: add feature to increase/decrease size (#1048)

This commit is contained in:
Andreas Bissinger 2022-03-06 11:33:28 +01:00 committed by GitHub
parent ceadf83809
commit 7cb689795e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 3 deletions

View File

@ -90,7 +90,12 @@ let g:nvim_tree_icons = {
nnoremap <C-n> :NvimTreeToggle<CR>
nnoremap <leader>r :NvimTreeRefresh<CR>
nnoremap <leader>n :NvimTreeFindFile<CR>
" NvimTreeOpen, NvimTreeClose, NvimTreeFocus, NvimTreeFindFileToggle, and NvimTreeResize are also available if you need them
" More available functions:
" NvimTreeOpen
" NvimTreeClose
" NvimTreeFocus
" NvimTreeFindFileToggle
" NvimTreeResize
set termguicolors " this variable must be enabled for colors to be applied properly

View File

@ -61,7 +61,11 @@ Print clipboard content for both cut and copy
|:NvimTreeResize| *:NvimTreeResize*
Resize the NvimTree window to the given size. Example: `:NvimTreeResize 50`
resizes the window to the width of 50.
resizes the window to the width of 50. If the size starts with "+" or "-" it
adds or removes the given value to the current window width.
Example `:NvimTreeResize -20` removes the value 20 from the current width. And
`:NvimTreeResize +20` adds the value 20 to the current width.
==============================================================================
SETUP *nvim-tree.setup*

View File

@ -276,7 +276,7 @@ local function setup_vim_commands()
command! NvimTreeClipboard lua require'nvim-tree.actions.copy-paste'.print_clipboard()
command! NvimTreeFindFile lua require'nvim-tree'.find_file(true)
command! NvimTreeFindFileToggle lua require'nvim-tree'.toggle(true)
command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize(<args>)
command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize("<args>")
]]
end

View File

@ -175,6 +175,24 @@ function M.open(options)
end
function M.resize(size)
if type(size) == "string" then
size = vim.trim(size)
local first_char = size:sub(1, 1)
size = tonumber(size)
if first_char == "+" or first_char == "-" then
size = M.View.width + size
end
end
if type(size) ~= "number" then
return
end
if size <= 0 then
return
end
if size then
M.View.width = size
M.View.height = size