add view.indent_markers (#1134)

This commit is contained in:
Alexander Courtis
2022-04-10 23:40:29 +10:00
committed by GitHub
parent 83fe370d52
commit d5e4f0655b
6 changed files with 72 additions and 13 deletions

View File

@@ -38,7 +38,6 @@ Note that options under the `g:` command should be set **BEFORE** running the se
These are being migrated to the setup function incrementally, check [this issue](https://github.com/kyazdani42/nvim-tree.lua/issues/674) if you encounter any problems related to configs not working after update.
```vim
" vimrc
let g:nvim_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
let g:nvim_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).
let g:nvim_tree_highlight_opened_files = 1 "0 by default, will enable folder and file icon highlight for opened files/directories.
let g:nvim_tree_root_folder_modifier = ':~' "This is the default. See :help filename-modifiers for more options
@@ -59,7 +58,7 @@ let g:nvim_tree_show_icons = {
"1 by default, notice that if 'files' is 1, it will only display
"if nvim-web-devicons is installed and on your runtimepath.
"if folder is 1, you can also tell folder_arrows 1 to show small arrows next to the folder icons.
"but this will not work when you set indent_markers (because of UI conflict)
"but this will not work when you set renderer.indent_markers.enable (because of UI conflict)
" default will show icon by default if no icon is provided
" default shows no icon by default
@@ -144,6 +143,16 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
},
},
},
renderer = {
indent_markers = {
enable = false,
icons = {
corner = "",
edge = "",
none = " ",
},
},
},
hijack_directories = {
enable = true,
auto_open = true,

View File

@@ -111,6 +111,16 @@ function.
},
},
},
renderer = {
indent_markers = {
enable = false,
icons = {
corner = "└ ",
edge = "│ ",
none = " ",
},
},
},
hijack_directories = {
enable = true,
auto_open = true,
@@ -408,6 +418,19 @@ Here is a list of the options available in the setup call:
type: list of `{ key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }`
default: `{}`
*nvim-tree.renderer*
- |renderer|: UI rendering setup
- |renderer.indent_markers|: configuration options for tree indent markers
- |renderer.indent_markers.enable|: display indent markers when folders are open
type: `boolean`
default: `false`
- |renderer.indent_markers.icons|: icons shown before the file/directory
type: `table`
default: `{ corner = "└ ", edge = "│ ", none = " ", }`
*nvim-tree.filters*
|filters|: filtering options
@@ -543,7 +566,7 @@ is installed and in your |runtimepath|
(https://github.com/kyazdani42/nvim-web-devicons)
if folder is 1, you can also set `folder_arrows = 1` to show small arrows
next to the folder icons but this will not work when you set
|g:nvim_tree_indent_markers| (because of UI conflict).
|renderer.indent_markers.enable| (because of UI conflict).
|g:nvim_tree_highlight_opened_files| *g:nvim_tree_highlight_opened_files*
@@ -599,11 +622,6 @@ You can set icons for:
You can enable file highlight for git attributes by setting this property.
This can be used with or without the icons.
|g:nvim_tree_indent_markers| *g:nvim_tree_indent_markers*
Can be `0` or `1`. When `1`, will display indent markers when folders are open
Default is 0
|g:nvim_tree_root_folder_modifier| *g:nvim_tree_root_folder_modifier*
In what format to show root folder. See `:help filename-modifiers` for

View File

@@ -336,6 +336,16 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
},
},
renderer = {
indent_markers = {
enable = false,
icons = {
corner = "",
edge = "",
none = " ",
},
},
},
hijack_directories = {
enable = true,
auto_open = true,
@@ -446,6 +456,7 @@ function M.setup(conf)
require("nvim-tree.git").setup(opts)
require("nvim-tree.view").setup(opts)
require("nvim-tree.lib").setup(opts)
require("nvim-tree.renderer").setup(opts)
setup_vim_commands()
setup_autocommands(opts)

View File

@@ -169,6 +169,13 @@ local migrations = {
o.actions.change_dir.global = vim.g.nvim_tree_change_dir_global == 1
end
end,
nvim_tree_indent_markers = function(o)
utils.table_create_missing(o, "renderer.indent_markers")
if o.renderer.indent_markers.enable == nil then
o.renderer.indent_markers.enable = vim.g.nvim_tree_indent_markers == 1
end
end,
}
function M.migrate_legacy_options(opts)

View File

@@ -256,7 +256,7 @@ function M.draw()
hl = {}
icon_state = _icons.get_config()
local show_arrows = vim.g.nvim_tree_indent_markers ~= 1
local show_arrows = not M.config.indent_markers.enable
and icon_state.show_folder_icon
and icon_state.show_folder_arrows
_padding.reload_padding_function()
@@ -289,4 +289,12 @@ function M.render_hl(bufnr)
end
end
function M.setup(opts)
M.config = {
indent_markers = opts.renderer.indent_markers,
}
require("nvim-tree.renderer.padding").setup(opts)
end
return M

View File

@@ -21,11 +21,11 @@ local function get_padding_indent_markers(depth, idx, tree, _, markers)
markers[rdepth] = idx ~= #tree.nodes
for i = 1, rdepth do
if idx == #tree.nodes and i == rdepth then
padding = padding .. ""
padding = padding .. M.config.indent_markers.icons.corner
elseif markers[i] then
padding = padding .. ""
padding = padding .. M.config.indent_markers.icons.edge
else
padding = padding .. " "
padding = padding .. M.config.indent_markers.icons.none
end
end
end
@@ -39,9 +39,15 @@ function M.reload_padding_function()
M.get_padding = get_padding_arrows(icon_state)
end
if vim.g.nvim_tree_indent_markers == 1 then
if M.config.indent_markers.enable then
M.get_padding = get_padding_indent_markers
end
end
function M.setup(opts)
M.config = {
indent_markers = opts.renderer.indent_markers,
}
end
return M