fix(preview): highlight hunk

Fixes #534
This commit is contained in:
Lewis Russell 2022-04-18 13:06:33 +01:00
parent cd1c11cf09
commit 1bff8d610f
3 changed files with 20 additions and 14 deletions

View File

@ -568,9 +568,9 @@ end
local function insert_hunk_hlmarks(fmt, hunk)
for _, line in ipairs(fmt) do
for _, s in ipairs(line) do
if s[1] == '<hunk>' then
local orig_hl = s[2]
s[2] = hlmarks_for_hunk(hunk, orig_hl)
local hl = s[2]
if s[1] == '<hunk>' and type(hl) == "string" then
s[2] = hlmarks_for_hunk(hunk, hl)
end
end
end
@ -595,17 +595,19 @@ M.preview_hunk = noautocmd(function()
if not hunk then return end
local lines_spec = lines_format({
local lines_fmt = {
{ { 'Hunk <hunk_no> of <num_hunks>', 'Title' } },
{ { '<hunk>', 'Normal' } },
}, {
}
insert_hunk_hlmarks(lines_fmt, hunk)
local lines_spec = lines_format(lines_fmt, {
hunk_no = index,
num_hunks = #bcache.hunks,
hunk = gs_hunks.patch_lines(hunk, vim.bo[cbuf].fileformat),
})
insert_hunk_hlmarks(lines_spec, hunk)
popup.create(lines_spec, config.preview_config)
end)

View File

@ -568,9 +568,9 @@ end
local function insert_hunk_hlmarks(fmt: popup.LinesSpec, hunk: Hunk)
for _, line in ipairs(fmt) do
for _, s in ipairs(line) do
if s[1] == '<hunk>' then
local orig_hl = s[2] as string
s[2] = hlmarks_for_hunk(hunk, orig_hl)
local hl = s[2]
if s[1] == '<hunk>' and hl is string then
s[2] = hlmarks_for_hunk(hunk, hl)
end
end
end
@ -595,17 +595,19 @@ M.preview_hunk = noautocmd(function()
if not hunk then return end
local lines_spec = lines_format({
local lines_fmt = {
{{'Hunk <hunk_no> of <num_hunks>', 'Title'}},
{{'<hunk>', 'Normal' }}
}, {
}
insert_hunk_hlmarks(lines_fmt, hunk)
local lines_spec = lines_format(lines_fmt, {
hunk_no = index,
num_hunks = #bcache.hunks,
hunk = gs_hunks.patch_lines(hunk, vim.bo[cbuf].fileformat),
})
insert_hunk_hlmarks(lines_spec, hunk)
popup.create(lines_spec, config.preview_config)
end)

View File

@ -477,6 +477,8 @@ global record vim
end
end
notify: function(string, integer, table)
pretty_print: function(any)
split: function(string, string): {string}
split: function(string, string, boolean): {string}