From d51ed722eda014a4f48924161fe58d40f67f877f Mon Sep 17 00:00:00 2001 From: Kiyan Date: Wed, 2 Jun 2021 18:45:25 +0200 Subject: [PATCH] add small arrows before folders (#427) --- README.md | 7 ++++++- doc/nvim-tree-lua.txt | 8 +++++++- lua/nvim-tree/config.lua | 5 ++++- lua/nvim-tree/renderer.lua | 14 +++++++++++++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 65990132..ec6c5d02 100644 --- a/README.md +++ b/README.md @@ -56,10 +56,13 @@ let g:nvim_tree_show_icons = { \ 'git': 1, \ 'folders': 0, \ 'files': 0, + \ 'folder_arrows': 0, \ } "If 0, do not show the icons for one of 'git' 'folder' and 'files' "1 by default, notice that if 'files' is 1, it will only display -"if nvim-web-devicons is installed and on your runtimepath +"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) " default will show icon by default if no icon is provided " default shows no icon by default @@ -76,6 +79,8 @@ let g:nvim_tree_icons = { \ 'ignored': "◌" \ }, \ 'folder': { + \ 'arrow_open': "", + \ 'arrow_closed': "", \ 'default': "", \ 'open': "", \ 'empty': "", diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 0633f6a0..8e753169 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -87,13 +87,17 @@ can disable icons per type: let g:nvim_tree_show_icons = { \ 'git': 1, \ 'folders': 1, - \ 'files': 1 + \ 'files': 1, + \ 'folder_arrows': 1, \} Can be one of `1` and `0` for each key. By default the tree will try to render the icons. The `files` key can only work if `nvim-web-devicons` 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). |g:nvim_tree_highlight_opened_files| *g:nvim_tree_highlight_opened_files* @@ -127,6 +131,8 @@ You can set icons for: \ 'deleted': "", \ }, \ 'folder': { + \ 'arrow_open': "", + \ 'arrow_closed': "", \ 'default': "", \ 'open': "", \ 'empty': "", diff --git a/lua/nvim-tree/config.lua b/lua/nvim-tree/config.lua index 195db4ed..48bd9b54 100644 --- a/lua/nvim-tree/config.lua +++ b/lua/nvim-tree/config.lua @@ -1,7 +1,7 @@ local M = {} function M.get_icon_state() - local show_icons = vim.g.nvim_tree_show_icons or { git = 1, folders = 1, files = 1 } + local show_icons = vim.g.nvim_tree_show_icons or { git = 1, folders = 1, files = 1, folder_arrows = 1 } local icons = { default = "", symlink = "", @@ -15,6 +15,8 @@ function M.get_icon_state() ignored = "◌" }, folder_icons = { + arrow_closed = "", + arrow_open = "", default = "", open = "", empty = "", @@ -60,6 +62,7 @@ function M.get_icon_state() show_file_icon = show_icons.files == 1 and vim.g.nvim_web_devicons == 1, show_folder_icon = show_icons.folders == 1, show_git_icon = show_icons.git == 1, + show_folder_arrows = show_icons.folder_arrows == 1, icons = icons } end diff --git a/lua/nvim-tree/renderer.lua b/lua/nvim-tree/renderer.lua index e490294a..c6a390d3 100644 --- a/lua/nvim-tree/renderer.lua +++ b/lua/nvim-tree/renderer.lua @@ -215,6 +215,16 @@ local get_padding = function(depth) return string.rep(' ', depth) end +if icon_state.show_folder_icon and icon_state.show_folder_arrows then + get_padding = function(depth, _, _, node) + if node.entries then + local icon = icon_state.icons.folder_icons[node.open and 'arrow_open' or 'arrow_closed'] + return string.rep(' ', depth - 2)..icon..' ' + end + return string.rep(' ', depth) + end +end + if vim.g.nvim_tree_indent_markers == 1 then get_padding = function(depth, idx, tree, _, markers) local padding = "" @@ -354,7 +364,9 @@ function M.draw(tree, reload) index = 0 lines = {} hl = {} - update_draw_data(tree, 0, {}) + + local show_arrows = icon_state.show_folder_icon and icon_state.show_folder_arrows + update_draw_data(tree, show_arrows and 1 or 0, {}) end api.nvim_buf_set_option(view.View.bufnr, 'modifiable', true)