add file highlight for git attributes and remove the space before the git icon

This commit is contained in:
kiyan42
2020-08-02 11:34:43 +02:00
parent c552a4f4f5
commit a25ac38db1
6 changed files with 80 additions and 15 deletions

View File

@@ -31,6 +31,7 @@ let g:lua_tree_auto_open = 1 "0 by default, opens the tree when typing `vim $DIR
let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window let g:lua_tree_auto_close = 1 "0 by default, closes the tree when it's the last window
let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer let g:lua_tree_follow = 1 "0 by default, this option allows the cursor to be updated when entering a buffer
let g:lua_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open let g:lua_tree_indent_markers = 1 "0 by default, this option shows indent markers when folders are open
let g:lua_tree_git_hl = 1 "0 by default, will enable file highlight for git attributes (can be used without the icons).
let g:lua_tree_show_icons = { let g:lua_tree_show_icons = {
\ 'git': 1, \ 'git': 1,
\ 'folders': 0, \ 'folders': 0,
@@ -130,7 +131,7 @@ The Netrw vim plugin is disabled, hence features like `gx` don't work accross yo
- Syntax highlighting ([exa](https://github.com/ogham/exa) like) - Syntax highlighting ([exa](https://github.com/ogham/exa) like)
- Change directory with `.` - Change directory with `.`
- Add / Rename / delete files - Add / Rename / delete files
- Git integration - Git integration (icons and file highlight)
- Indent markers - Indent markers
- Mouse support - Mouse support
- It's fast - It's fast

View File

@@ -100,7 +100,13 @@ when no icon is found for a file.
\ 'untracked': "★" \ 'untracked': "★"
\ } \ }
\ } \ }
<
|g:lua_tree_git_hl| *g:lua_tree_git_hl*
You can enable file highlight for git attributes by setting this property.
This can be used with or without the icons.
|g:lua_tree_follow| *g:lua_tree_follow* |g:lua_tree_follow| *g:lua_tree_follow*
Can be `0` or `1`. When `1`, will update the cursor to update to the correct Can be `0` or `1`. When `1`, will update the cursor to update to the correct
@@ -231,6 +237,7 @@ LuaTreeImageFile
LuaTreeMarkdownFile LuaTreeMarkdownFile
LuaTreeIndentMarker LuaTreeIndentMarker
<<<<<<< HEAD
LuaTreeLicenseIcon LuaTreeLicenseIcon
LuaTreeYamlIcon LuaTreeYamlIcon
LuaTreeTomlIcon LuaTreeTomlIcon
@@ -262,5 +269,14 @@ CursorLine
VertSplit VertSplit
CursorColumn CursorColumn
There are also links for file highlight with git properties
These all link to there Git equivalent
LuaTreeFileDirty
LuaTreeFileStaged
LuaTreeFileMerge
LuaTreeFileNew
LuaTreeFileRenamed
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View File

@@ -1,3 +1,4 @@
:LuaTreeClipboard nvim-tree-lua.txt /*:LuaTreeClipboard*
:LuaTreeClose nvim-tree-lua.txt /*:LuaTreeClose* :LuaTreeClose nvim-tree-lua.txt /*:LuaTreeClose*
:LuaTreeFindFile nvim-tree-lua.txt /*:LuaTreeFindFile* :LuaTreeFindFile nvim-tree-lua.txt /*:LuaTreeFindFile*
:LuaTreeOpen nvim-tree-lua.txt /*:LuaTreeOpen* :LuaTreeOpen nvim-tree-lua.txt /*:LuaTreeOpen*
@@ -6,7 +7,9 @@
g:lua_tree_auto_close nvim-tree-lua.txt /*g:lua_tree_auto_close* g:lua_tree_auto_close nvim-tree-lua.txt /*g:lua_tree_auto_close*
g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open* g:lua_tree_auto_open nvim-tree-lua.txt /*g:lua_tree_auto_open*
g:lua_tree_bindings nvim-tree-lua.txt /*g:lua_tree_bindings* g:lua_tree_bindings nvim-tree-lua.txt /*g:lua_tree_bindings*
g:lua_tree_disable_keybindings nvim-tree-lua.txt /*g:lua_tree_disable_keybindings*
g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow* g:lua_tree_follow nvim-tree-lua.txt /*g:lua_tree_follow*
g:lua_tree_git_hl nvim-tree-lua.txt /*g:lua_tree_git_hl*
g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons* g:lua_tree_icons nvim-tree-lua.txt /*g:lua_tree_icons*
g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore* g:lua_tree_ignore nvim-tree-lua.txt /*g:lua_tree_ignore*
g:lua_tree_indent_markers nvim-tree-lua.txt /*g:lua_tree_indent_markers* g:lua_tree_indent_markers nvim-tree-lua.txt /*g:lua_tree_indent_markers*

View File

@@ -105,7 +105,11 @@ local function get_links()
CursorLine = 'CursorLine', CursorLine = 'CursorLine',
VertSplit = 'VertSplit', VertSplit = 'VertSplit',
CursorColumn = 'CursorColumn', CursorColumn = 'CursorColumn',
FolderDirty = 'LuaTreeFolderName' FileDirty = 'LuaTreeGitDirty',
FileNew = 'LuaTreeGitNew',
FileRenamed = 'LuaTreeGitRenamed',
FileMerge = 'LuaTreeGitMerge',
FileStaged = 'LuaTreeGitStaged',
} }
end end

View File

@@ -196,7 +196,7 @@ function M.populate(entries, cwd)
table.insert(entries, file) table.insert(entries, file)
end end
if not icon_config.show_git_icon then if not icon_config.show_git_icon and vim.g.lua_tree_git_hl ~= 1 then
return return
end end

View File

@@ -49,6 +49,41 @@ if icon_state.show_file_icon then
end end
local get_git_icons = function() return "" end local get_git_icons = function() return "" end
local get_git_hl = function() return end
if vim.g.lua_tree_git_hl == 1 then
local git_hl = {
["M "] = { { hl = "LuaTreeFileStaged" } },
[" M"] = { { hl = "LuaTreeFileDirty" } },
["MM"] = {
{ hl = "LuaTreeFileStaged" },
{ hl = "LuaTreeFileDirty" }
},
["A "] = {
{ hl = "LuaTreeFileStaged" },
{ hl = "LuaTreeFileNew" }
},
["AM"] = {
{ hl = "LuaTreeFileStaged" },
{ hl = "LuaTreeFileNew" },
{ hl = "LuaTreeFileDirty" }
},
["??"] = { { hl = "LuaTreeFileNew" } },
["R "] = { { hl = "LuaTreeFileRenamed" } },
["UU"] = { { hl = "LuaTreeFileMerge" } },
dirty = { { hl = "LuaTreeFileDirty" } },
}
get_git_hl = function(node)
local git_status = node.git_status
if not git_status then return end
local icons = git_hl[git_status]
-- TODO: how would we determine hl color when multiple git status are active ?
return icons[1].hl
-- return icons[#icons].hl
end
end
if icon_state.show_git_icon then if icon_state.show_git_icon then
local git_icon_state = { local git_icon_state = {
["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" } }, ["M "] = { { icon = icon_state.icons.git_icons.staged, hl = "LuaTreeGitStaged" } },
@@ -138,26 +173,27 @@ local function update_draw_data(tree, depth, markers)
if depth > 0 then if depth > 0 then
table.insert(hl, { 'LuaTreeIndentMarker', index, 0, offset }) table.insert(hl, { 'LuaTreeIndentMarker', index, 0, offset })
end end
local git_hl = get_git_hl(node)
if node.entries then if node.entries then
local icon = get_folder_icon(node.open) local icon = get_folder_icon(node.open)
local git_icon = get_git_icons(node, index, offset, #icon+1) local git_icon = get_git_icons(node, index, offset, #icon+1) or ""
local git_display -- INFO: this is mandatory in order to keep gui attributes (bold/italics)
if git_icon and #git_icon ~= 0 then set_folder_hl(index, offset, #icon, #node.name+#git_icon, 'LuaTreeFolderName')
git_display = " "..git_icon if git_hl then
set_folder_hl(index, offset, #icon+#git_display, #node.name, 'LuaTreeFolderDirty') set_folder_hl(index, offset, #icon, #node.name+#git_icon, git_hl)
else
git_display = ""
set_folder_hl(index, offset, #icon, #node.name, 'LuaTreeFolderName')
end end
index = index + 1 index = index + 1
if node.open then if node.open then
table.insert(lines, padding..icon..git_display..node.name) table.insert(lines, padding..icon..git_icon..node.name)
update_draw_data(node, depth + 2, markers) update_draw_data(node, depth + 2, markers)
else else
table.insert(lines, padding..icon..git_display..node.name) table.insert(lines, padding..icon..git_icon..node.name)
end end
elseif node.link_to then elseif node.link_to then
table.insert(hl, { 'LuaTreeSymlink', index, offset, -1 }) 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..node.name..""..node.link_to)
index = index + 1 index = index + 1
@@ -173,11 +209,16 @@ local function update_draw_data(tree, depth, markers)
git_icons = get_git_icons(node, index, offset, #icon) git_icons = get_git_icons(node, index, offset, #icon)
end end
table.insert(lines, padding..icon..git_icons..node.name) table.insert(lines, padding..icon..git_icons..node.name)
if node.executable then if node.executable then
table.insert(hl, {'LuaTreeExecFile', index, offset+#icon+#git_icons, -1 }) table.insert(hl, {'LuaTreeExecFile', index, offset+#icon+#git_icons, -1 })
elseif picture[node.extension] then elseif picture[node.extension] then
table.insert(hl, {'LuaTreeImageFile', index, offset+#icon+#git_icons, -1 }) table.insert(hl, {'LuaTreeImageFile', index, offset+#icon+#git_icons, -1 })
end end
if git_hl then
table.insert(hl, {git_hl, index, offset+#icon+#git_icons, -1 })
end
index = index + 1 index = index + 1
end end
end end