feat: option to set path destination to parent folder when cursor is on a closed folder while creating files (#628)

This commit is contained in:
booperlv 2021-09-26 18:10:19 +08:00 committed by GitHub
parent 1edebb7894
commit 2a5d529219
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -92,6 +92,7 @@ let g:nvim_tree_disable_window_picker = 1 "0 by default, will disable the window
let g:nvim_tree_icon_padding = ' ' "one space by default, used for rendering the space between the icon and the filename. Use with caution, it could break rendering if you set an empty string depending on your font.
let g:nvim_tree_symlink_arrow = ' >> ' " defaults to ' ➛ '. used as a separator between symlinks' source and target.
let g:nvim_tree_respect_buf_cwd = 1 "0 by default, will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
let g:nvim_tree_create_in_closed_folder = 0 "1 by default, When creating files, sets the path of a file when cursor is on a closed folder to the parent folder when 0, and inside the folder when 1.
let g:nvim_tree_refresh_wait = 500 "1000 by default, control how often the tree can be refreshed, 1000 means the tree can be refresh once per 1000ms.
let g:nvim_tree_window_picker_exclude = {
\ 'filetype': [

View File

@ -373,6 +373,12 @@ Defaults to ' ➛ '. Used as a separator between symlinks' source and target.
Can be 0 or 1. 0 by default.
Will change cwd of nvim-tree to that of new buffer's when opening nvim-tree.
|g:nvim_tree_create_in_closed_folder| *g:nvim_tree_create_in_closed_folder*
Can be 0 or 1. 1 by default.
Creating a file when the cursor is on a closed folder will set the
path to be inside the closed folder when 1, and on the parent folder when 0.
==============================================================================
INFORMATIONS *nvim-tree-info*

View File

@ -57,8 +57,10 @@ function M.create(node)
}
end
local node_is_open = vim.g.nvim_tree_create_in_closed_folder == 1 or node.open
local add_into
if node.entries ~= nil then
if node.entries ~= nil and node_is_open then
add_into = utils.path_add_trailing(node.absolute_path)
else
add_into = node.absolute_path:sub(0, -(#node.name + 1))