add icon padding

This commit is contained in:
kiyan 2021-06-07 17:34:02 +02:00
parent 82f1598bd4
commit f1f14885f7
3 changed files with 13 additions and 6 deletions

View File

@ -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_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_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_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 = { let g:nvim_tree_window_picker_exclude = {
\ 'filetype': [ \ 'filetype': [
\ 'packer', \ 'packer',

View File

@ -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 When 1, moving cursor in the tree will position the cursor at the start
of the file on the current line. 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* INFORMATIONS *nvim-tree-info*

View File

@ -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}) table.insert(hl, {hl_group, line, depth+git_icon_len, -1})
end end
local icon_padding = vim.g.nvim_tree_icon_padding or " "
if icon_state.show_folder_icon then if icon_state.show_folder_icon then
get_folder_icon = function(open, is_symlink, has_children) get_folder_icon = function(open, is_symlink, has_children)
local n = "" local n = ""
@ -42,7 +44,7 @@ if icon_state.show_folder_icon then
n = icon_state.icons.folder_icons.empty n = icon_state.icons.folder_icons.empty
end end
end end
return n.." " return n..icon_padding
end end
set_folder_hl = function(line, depth, icon_len, name_len, hl_group) 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()}) 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 if hl_group then
table.insert(hl, { hl_group, line, depth, depth + #icon + 1 }) table.insert(hl, { hl_group, line, depth, depth + #icon + 1 })
end end
return icon.." " return icon..icon_padding
elseif string.match(extension, "%.(.*)") then elseif string.match(extension, "%.(.*)") then
-- If there are more extensions to the file, try to grab the icon for them recursively -- 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) return get_file_icon(fname, string.match(extension, "%.(.*)"), line, depth)
else 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
end end
@ -76,14 +78,14 @@ end
local get_symlink_icon = function() return icon_state.icons.symlink end local get_symlink_icon = function() return icon_state.icons.symlink end
if icon_state.show_file_icon then if icon_state.show_file_icon then
get_symlink_icon = function() 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
end end
local get_special_icon = function() return icon_state.icons.default end local get_special_icon = function() return icon_state.icons.default end
if icon_state.show_file_icon then if icon_state.show_file_icon then
get_special_icon = function() 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
end end
@ -204,7 +206,7 @@ if icon_state.show_git_icon then
end end
for _, v in ipairs(icons) do for _, v in ipairs(icons) do
table.insert(hl, { v.hl, line, depth+icon_len+#icon, depth+icon_len+#icon+#v.icon }) 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 end
return icon return icon