diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index 6d96b10..13995eb 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -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] == '' then - local orig_hl = s[2] - s[2] = hlmarks_for_hunk(hunk, orig_hl) + local hl = s[2] + if s[1] == '' 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 of ', 'Title' } }, { { '', '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) diff --git a/teal/gitsigns/actions.tl b/teal/gitsigns/actions.tl index 8383f4f..355fb91 100644 --- a/teal/gitsigns/actions.tl +++ b/teal/gitsigns/actions.tl @@ -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] == '' then - local orig_hl = s[2] as string - s[2] = hlmarks_for_hunk(hunk, orig_hl) + local hl = s[2] + if s[1] == '' 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 of ', 'Title'}}, {{'', '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) diff --git a/types/types.d.tl b/types/types.d.tl index efe2c68..86a1dd0 100644 --- a/types/types.d.tl +++ b/types/types.d.tl @@ -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}