From 7cb689795e215b85252928af6607fdf4a59314ee Mon Sep 17 00:00:00 2001 From: Andreas Bissinger Date: Sun, 6 Mar 2022 11:33:28 +0100 Subject: [PATCH] feature: add feature to increase/decrease size (#1048) --- README.md | 7 ++++++- doc/nvim-tree-lua.txt | 6 +++++- lua/nvim-tree.lua | 2 +- lua/nvim-tree/view.lua | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 49937ce7..f0f8260d 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,12 @@ let g:nvim_tree_icons = { nnoremap :NvimTreeToggle nnoremap r :NvimTreeRefresh nnoremap n :NvimTreeFindFile -" 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 diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 5ac6a816..d0e17947 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -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* diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 9a41ac17..fb781cd6 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -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() + command! -nargs=1 NvimTreeResize lua require'nvim-tree'.resize("") ]] end diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index af211c7e..a867b537 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -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