diff --git a/lua/gitsigns.lua b/lua/gitsigns.lua index df95c58..2851060 100644 --- a/lua/gitsigns.lua +++ b/lua/gitsigns.lua @@ -591,7 +591,7 @@ local function add_debug_functions() local item = raw_item return { '...', length = #item, head = item[1] } elseif not vim.tbl_isempty(raw_item) and vim.tbl_contains({ - 'hunks', 'staged_diffs', }, key) then + 'staged_diffs', }, key) then return { '...', length = #vim.tbl_keys(raw_item) } elseif key == 'pending_signs' then local keys = vim.tbl_keys(raw_item) @@ -748,9 +748,7 @@ local function select_hunk() return end - local start, dend = gs_hunks.get_range(hunk) - - vim.cmd('normal! ' .. start .. 'GV' .. dend .. 'G') + vim.cmd('normal! ' .. hunk.start .. 'GV' .. hunk.dend .. 'G') end local blame_line = void_async(function() diff --git a/lua/gitsigns/hunks.lua b/lua/gitsigns/hunks.lua index 2f515bf..b719205 100644 --- a/lua/gitsigns/hunks.lua +++ b/lua/gitsigns/hunks.lua @@ -73,26 +73,15 @@ function M.parse_diff_line(line) return hunk end -function M.get_range(hunk) - local dend = hunk.dend - if hunk.type == "change" then - local add, remove = hunk.added.count, hunk.removed.count - if add > remove then - dend = dend + add - remove - end - end - return hunk.start, dend -end - function M.process_hunks(hunks) local signs = {} for _, hunk in ipairs(hunks) do + local count = hunk.type == 'add' and hunk.added.count or hunk.removed.count for i = hunk.start, hunk.dend do local topdelete = hunk.type == 'delete' and i == 0 local changedelete = hunk.type == 'change' and hunk.removed.count > hunk.added.count and i == hunk.dend - local count = hunk.type == 'add' and hunk.added.count or hunk.removed.count - local lnum = topdelete and 1 or i - signs[lnum] = { + + signs[topdelete and 1 or i] = { type = topdelete and 'topdelete' or changedelete and 'changedelete' or hunk.type, count = i == hunk.start and count, } @@ -100,12 +89,11 @@ function M.process_hunks(hunks) if hunk.type == "change" then local add, remove = hunk.added.count, hunk.removed.count if add > remove then - local count = add - remove - for i = 1, count do - local lnum = hunk.dend + i - signs[lnum] = { + local count_diff = add - remove + for i = 1, count_diff do + signs[hunk.dend + i] = { type = 'add', - count = i == 1 and count, + count = i == 1 and count_diff, } end end @@ -183,9 +171,7 @@ function M.find_hunk(lnum, hunks) return hunk end - local start, dend = M.get_range(hunk) - - if start <= lnum and dend >= lnum then + if hunk.start <= lnum and hunk.dend >= lnum then return hunk end end diff --git a/teal/gitsigns.tl b/teal/gitsigns.tl index 52e0321..0ee694e 100644 --- a/teal/gitsigns.tl +++ b/teal/gitsigns.tl @@ -591,7 +591,7 @@ local function add_debug_functions() local item = raw_item as {string} return { '...', length=#item, head=item[1] } elseif not vim.tbl_isempty(raw_item) and vim.tbl_contains({ - 'hunks', 'staged_diffs' }, key) then + 'staged_diffs' }, key) then return { '...', length=#vim.tbl_keys(raw_item) } elseif key == 'pending_signs' then local keys = vim.tbl_keys(raw_item) @@ -748,9 +748,7 @@ local function select_hunk() return end - local start, dend = gs_hunks.get_range(hunk) - - vim.cmd('normal! '..start..'GV'..dend..'G') + vim.cmd('normal! '..hunk.start..'GV'..hunk.dend..'G') end local blame_line = void_async(function() diff --git a/teal/gitsigns/hunks.tl b/teal/gitsigns/hunks.tl index 9d1c7a1..8c0b182 100644 --- a/teal/gitsigns/hunks.tl +++ b/teal/gitsigns/hunks.tl @@ -73,26 +73,15 @@ function M.parse_diff_line(line: string): Hunk return hunk end -function M.get_range(hunk: Hunk): number, number - local dend = hunk.dend - if hunk.type == "change" then - local add, remove = hunk.added.count, hunk.removed.count - if add > remove then - dend = dend + add - remove - end - end - return hunk.start, dend -end - function M.process_hunks(hunks: {Hunk}): {integer:Sign} local signs = {} for _, hunk in ipairs(hunks) do + local count = hunk.type == 'add' and hunk.added.count or hunk.removed.count for i = hunk.start, hunk.dend do local topdelete = hunk.type == 'delete' and i == 0 local changedelete = hunk.type == 'change' and hunk.removed.count > hunk.added.count and i == hunk.dend - local count = hunk.type == 'add' and hunk.added.count or hunk.removed.count - local lnum = topdelete and 1 or i - signs[lnum] = { + -- topdelete signs get placed one row lower + signs[topdelete and 1 or i] = { type = topdelete and 'topdelete' or changedelete and 'changedelete' or hunk.type, count = i == hunk.start and count } @@ -100,12 +89,11 @@ function M.process_hunks(hunks: {Hunk}): {integer:Sign} if hunk.type == "change" then local add, remove = hunk.added.count, hunk.removed.count if add > remove then - local count = add - remove - for i = 1, count do - local lnum = hunk.dend + i - signs[lnum] = { + local count_diff = add - remove + for i = 1, count_diff do + signs[hunk.dend + i] = { type = 'add', - count = i == 1 and count + count = i == 1 and count_diff } end end @@ -183,9 +171,7 @@ function M.find_hunk(lnum: number, hunks: {Hunk}): Hunk return hunk end - local start, dend = M.get_range(hunk) - - if start <= lnum and dend >= lnum then + if hunk.start <= lnum and hunk.dend >= lnum then return hunk end end