feat(blame): added config.current_line_blame_formatter_nc

Used to format uncommitted lines.

Resolves: #476
This commit is contained in:
Lewis Russell 2022-04-14 16:08:14 +01:00 committed by Lewis Russell
parent a6a772dd3a
commit dd60a8845d
5 changed files with 39 additions and 10 deletions

View File

@ -787,6 +787,15 @@ current_line_blame_formatter *gitsigns-config-current_line_blame_formatter*
field of |nvim_buf_set_extmark| and thus must be a list of
[text, highlight] tuples.
current_line_blame_formatter_nc
*gitsigns-config-current_line_blame_formatter_nc*
Type: `string|function`, Default: `' <author>'`
String or function used to format the virtual text of
|gitsigns-config-current_line_blame| for lines that aren't committed.
See |gitsigns-config-current_line_blame_formatter| for more information.
trouble *gitsigns-config-trouble*
Type: `boolean`, Default: true if installed

View File

@ -109,6 +109,7 @@ local M = {Config = {DiffOpts = {}, SignsConfig = {}, watch_gitdir = {}, current
M.config = {}
@ -557,6 +558,17 @@ M.schema = {
]],
},
current_line_blame_formatter_nc = {
type = { 'string', 'function' },
default = ' <author>',
description = [[
String or function used to format the virtual text of
|gitsigns-config-current_line_blame| for lines that aren't committed.
See |gitsigns-config-current_line_blame_formatter| for more information.
]],
},
trouble = {
type = 'boolean',
default = function()

View File

@ -84,10 +84,6 @@ local function expand_blame_format(fmt, name, info)
info.author = 'You'
end
if info.author == 'Not Committed Yet' then
return info.author
end
for k, v in pairs({
author_time = info.author_time,
committer_time = info.committer_time,
@ -182,7 +178,9 @@ local update = void(function()
api.nvim_buf_set_var(bufnr, 'gitsigns_blame_line_dict', result)
if opts.virt_text and result then
local virt_text
local clb_formatter = config.current_line_blame_formatter
local clb_formatter = result.author == 'Not Committed Yet' and
config.current_line_blame_formatter_nc or
config.current_line_blame_formatter
if type(clb_formatter) == "string" then
virt_text = { {
expand_blame_format(clb_formatter, bcache.git_obj.repo.username, result),

View File

@ -71,6 +71,7 @@ local record M
end
current_line_blame_formatter: string|function(string, {string:any}, current_line_blame_formatter_opts): {{string,string}}
current_line_blame_formatter_nc: string|function(string, {string:any}, current_line_blame_formatter_opts): {{string,string}}
record current_line_blame_opts
virt_text: boolean
@ -557,6 +558,17 @@ M.schema = {
]]
},
current_line_blame_formatter_nc = {
type = {'string', 'function'},
default = ' <author>',
description = [[
String or function used to format the virtual text of
|gitsigns-config-current_line_blame| for lines that aren't committed.
See |gitsigns-config-current_line_blame_formatter| for more information.
]]
},
trouble = {
type = 'boolean',
default = function(): boolean

View File

@ -84,10 +84,6 @@ local function expand_blame_format(fmt: string, name: string, info: BlameInfo):
info.author = 'You'
end
if info.author == 'Not Committed Yet' then
return info.author
end
for k, v in pairs{
author_time = info.author_time,
committer_time = info.committer_time,
@ -182,7 +178,9 @@ local update = void(function()
api.nvim_buf_set_var(bufnr, 'gitsigns_blame_line_dict', result)
if opts.virt_text and result then
local virt_text: {{string, string}}
local clb_formatter = config.current_line_blame_formatter
local clb_formatter = result.author == 'Not Committed Yet' and
config.current_line_blame_formatter_nc or
config.current_line_blame_formatter
if clb_formatter is string then
virt_text = {{
expand_blame_format(clb_formatter, bcache.git_obj.repo.username, result),