feat(renderer): add ability to set git icons in signcolumn (#1242)

This commit is contained in:
Kiyan
2022-05-14 09:54:27 +02:00
committed by GitHub
parent 46014449b6
commit f8312cd06f
5 changed files with 42 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ function Builder.new(root_cwd)
highlights = {},
lines = {},
markers = {},
signs = {},
root_cwd = root_cwd,
}, Builder)
end
@@ -61,9 +62,11 @@ function Builder:configure_git_icons_padding(padding)
end
function Builder:configure_git_icons_placement(where)
where = where or "before"
self.is_git_before = where == "before"
self.is_git_after = not self.is_git_before
if where == "signcolumn" then
vim.fn.sign_unplace(git.SIGN_GROUP)
self.is_git_sign = true
end
self.is_git_after = where == "after" and not self.is_git_sign
return self
end
@@ -109,7 +112,7 @@ function Builder:_build_folder(node, padding, git_hl, git_icons_tbl)
local foldername = name .. self.trailing_slash
local git_icons = self:_unwrap_git_data(git_icons_tbl, offset + #icon + (self.is_git_after and #foldername + 1 or 0))
local fname_starts_at = offset + #icon + (self.is_git_before and #git_icons or 0)
local fname_starts_at = offset + #icon + (self.is_git_after and 0 or #git_icons)
local line = self:_format_line(padding .. icon, foldername, git_icons)
self:_insert_line(line)
@@ -226,6 +229,12 @@ function Builder:_build_line(tree, node, idx)
local git_highlight = git.get_highlight(node)
local git_icons_tbl = git.get_icons(node)
if self.is_git_sign and git_icons_tbl and #git_icons_tbl > 0 then
local git_info = git_icons_tbl[1]
table.insert(self.signs, { sign = git_info.hl, lnum = self.index + 1 })
git_icons_tbl = {}
end
local is_folder = node.nodes ~= nil
local is_symlink = node.link_to ~= nil
@@ -270,7 +279,7 @@ function Builder:build_header(show_header)
end
function Builder:unwrap()
return self.lines, self.highlights
return self.lines, self.highlights, self.signs
end
return Builder