Fallback to default icon for symlinks and fix padding

Fixes https://github.com/kyazdani42/nvim-tree.lua/issues/80
This commit is contained in:
Santos Gallegos 2020-08-03 18:09:50 -05:00
parent 505d63a3e7
commit bbcc5db4cb
4 changed files with 33 additions and 6 deletions

View File

@ -53,6 +53,7 @@ let g:lua_tree_bindings = {
\ 'edit_tab': '<C-t>',
\ 'toggle_ignored': 'I',
\ 'toggle_dotfiles': 'H',
\ 'refresh': 'R',
\ 'preview': '<Tab>',
\ 'cd': '<C-]>',
\ 'create': 'a',
@ -73,6 +74,7 @@ let g:lua_tree_bindings = {
" default shows no icon by default
let g:lua_tree_icons = {
\ 'default': '',
\ 'symlink': '',
\ 'git': {
\ 'unstaged': "✗",
\ 'staged': "✓",
@ -119,6 +121,7 @@ highlight LuaTreeFolderIcon guibg=blue
- `<Tab>` will open the file as a preview (keeps the cursor in the tree)
- `I` will toggle visibility of folders hidden via |g:lua_tree_ignore|
- `H` will toggle visibility of dotfiles (files/folders starting with a `.`)
- `R` will refresh the tree
- `gx` opens the file with the `open` command on MACOS and `xdg-open` in linux
- Double left click acts like `<CR>`
- Double right click acts like `<C-]>`
@ -127,7 +130,7 @@ highlight LuaTreeFolderIcon guibg=blue
This plugin is very fast because it uses the `libuv` `scandir` and `scandir_next` functions instead of spawning an `ls` process which can get slow on large files when combining with `stat` to get file informations.
The Netrw vim plugin is disabled, hence features like `gx` don't work accross your windows/buffers. You could use a plugin like [this one](https://github.com/stsewd/gx-extended.vim) if you wish to use that feature.
The Netrw vim plugin is disabled, hence features like `gx` don't work across your windows/buffers. You could use a plugin like [this one](https://github.com/stsewd/gx-extended.vim) if you wish to use that feature.
## Features
- Open file in current buffer or in split with FzF like bindings (`<CR>`, `<C-v>`, `<C-x>`, `<C-t>`)

View File

@ -87,11 +87,16 @@ is installed and in your |runtimepath|
|g:lua_tree_icons| *g:lua_tree_icons*
You can set some icons for the git status and the default icon that shows
when no icon is found for a file.
You can set icons for:
- The git status.
- The default icon that shows when no icon is found for a file
or if you are not using icons.
- Symlinks. If an icon is not provided, the `default` icon is used.
>
let g:lua_tree_icons = {
\ 'default': '',
\ 'symlink': '',
\ 'git': {
\ 'unstaged': "✗",
\ 'staged': "✓",

View File

@ -4,6 +4,7 @@ function M.get_icon_state()
local show_icons = vim.g.lua_tree_show_icons or { git = 1, folders = 1, files = 1 }
local icons = {
default = "",
symlink = "",
git_icons = {
unstaged = "",
staged = "",
@ -21,6 +22,10 @@ function M.get_icon_state()
if user_icons then
if user_icons.default then
icons.default = user_icons.default
icons.symlink = user_icons.default
end
if user_icons.symlink then
icons.symlink = user_icons.symlink
end
for key, val in pairs(user_icons.git or {}) do
if icons.git_icons[key] then

View File

@ -48,6 +48,20 @@ if icon_state.show_file_icon then
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 ""
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.." "
end
end
local get_git_icons = function() return "" end
local get_git_hl = function() return end
@ -195,17 +209,17 @@ local function update_draw_data(tree, depth, markers)
table.insert(lines, padding..icon..git_icon..node.name)
end
elseif node.link_to then
local icon = get_symlink_icon()
local link_hl = git_hl or 'LuaTreeSymlink'
table.insert(hl, { link_hl, index, offset, -1 })
table.insert(lines, padding..node.name..""..node.link_to)
table.insert(lines, padding..icon..node.name..""..node.link_to)
index = index + 1
else
local icon
local git_icons
if special[node.name] then
icon = icon_state.icons.default
if icon ~= "" then icon = icon.." " end
icon = get_special_icon()
git_icons = get_git_icons(node, index, offset, 0)
table.insert(hl, {'LuaTreeSpecialFile', index, offset+#git_icons, -1})
else