diff --git a/README.md b/README.md index 3c1a0cdf..64c7854c 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index a6ceddf7..36bfd9eb 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -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 diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index b87f0669..fd34be0f 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -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) diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 92fd1676..f4023c62 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -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) diff --git a/lua/nvim-tree/renderer/init.lua b/lua/nvim-tree/renderer/init.lua index cdedda59..552513f8 100644 --- a/lua/nvim-tree/renderer/init.lua +++ b/lua/nvim-tree/renderer/init.lua @@ -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 diff --git a/lua/nvim-tree/renderer/padding.lua b/lua/nvim-tree/renderer/padding.lua index a8f9200a..d4f232cc 100644 --- a/lua/nvim-tree/renderer/padding.lua +++ b/lua/nvim-tree/renderer/padding.lua @@ -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