From f1f14885f7b0be98f07b3a67261bdb5c811dd55e Mon Sep 17 00:00:00 2001 From: kiyan Date: Mon, 7 Jun 2021 17:34:02 +0200 Subject: [PATCH] add icon padding --- README.md | 1 + doc/nvim-tree-lua.txt | 4 ++++ lua/nvim-tree/renderer.lua | 14 ++++++++------ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4d186dab..782a18d3 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ let g:nvim_tree_group_empty = 1 " 0 by default, compact folders that only contai let g:nvim_tree_lsp_diagnostics = 1 "0 by default, will show lsp diagnostics in the signcolumn. See :help nvim_tree_lsp_diagnostics let g:nvim_tree_disable_window_picker = 1 "0 by default, will disable the window picker. let g:nvim_tree_hijack_cursor = 0 "1 by default, when moving cursor in the tree, will position the cursor at the start of the file on the current line +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_window_picker_exclude = { \ 'filetype': [ \ 'packer', diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 3906c046..2b3c1ad6 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -293,6 +293,10 @@ Can be 0 or 1. 1 by default. When 1, moving cursor in the tree will position the cursor at the start of the file on the current line. +|g:nvim_tree_icon_padding| *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. + ============================================================================== INFORMATIONS *nvim-tree-info* diff --git a/lua/nvim-tree/renderer.lua b/lua/nvim-tree/renderer.lua index 31fbc0cd..75f03998 100644 --- a/lua/nvim-tree/renderer.lua +++ b/lua/nvim-tree/renderer.lua @@ -22,6 +22,8 @@ local set_folder_hl = function(line, depth, git_icon_len, _, hl_group) table.insert(hl, {hl_group, line, depth+git_icon_len, -1}) end +local icon_padding = vim.g.nvim_tree_icon_padding or " " + if icon_state.show_folder_icon then get_folder_icon = function(open, is_symlink, has_children) local n = "" @@ -42,7 +44,7 @@ if icon_state.show_folder_icon then n = icon_state.icons.folder_icons.empty end end - return n.." " + return n..icon_padding end set_folder_hl = function(line, depth, icon_len, name_len, hl_group) table.insert(hl, {hl_group, line, depth+icon_len, depth+icon_len+name_len+get_trailing_length()}) @@ -62,12 +64,12 @@ if icon_state.show_file_icon then if hl_group then table.insert(hl, { hl_group, line, depth, depth + #icon + 1 }) end - return icon.." " + return icon..icon_padding elseif string.match(extension, "%.(.*)") then -- If there are more extensions to the file, try to grab the icon for them recursively return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth) else - return #icon_state.icons.default > 0 and icon_state.icons.default.." " or "" + return #icon_state.icons.default > 0 and icon_state.icons.default..icon_padding or "" end end @@ -76,14 +78,14 @@ end local get_symlink_icon = function() return icon_state.icons.symlink end if icon_state.show_file_icon then get_symlink_icon = function() - return #icon_state.icons.symlink > 0 and icon_state.icons.symlink.." " or "" + return #icon_state.icons.symlink > 0 and icon_state.icons.symlink..icon_padding or "" end end local get_special_icon = function() return icon_state.icons.default end if icon_state.show_file_icon then get_special_icon = function() - return #icon_state.icons.default > 0 and icon_state.icons.default.." " or "" + return #icon_state.icons.default > 0 and icon_state.icons.default..icon_padding or "" end end @@ -204,7 +206,7 @@ if icon_state.show_git_icon then end for _, v in ipairs(icons) do table.insert(hl, { v.hl, line, depth+icon_len+#icon, depth+icon_len+#icon+#v.icon }) - icon = icon..v.icon.." " + icon = icon..v.icon..icon_padding end return icon