Skip to content

Commit

Permalink
Clear all old signs before reapplying
Browse files Browse the repository at this point in the history
The previous implementation worked under the assumption that applying a
sign would overwrite any existing signs in the signcol. After reading :h
signcolumn it was clear that they were just getting added to a list and
the top priority sign was being rendered.

If a user had configured a signcolumn with more than 1 col then they
would see duplicate Hunk signs.

This fixes the issue by clearing all Hunk signs on a buffer before
reapplying new ones.

Fixes #2
  • Loading branch information
julienvincent committed Jul 24, 2024
1 parent cad38b2 commit d79dcc0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lua/hunk/api/signs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ local M = {
},
}

function M.clear_signs(buf)
vim.fn.sign_unplace("Hunk", {
buffer = buf,
})
end

function M.place_sign(buf, sign, linenr)
vim.fn.sign_place(0, "Hunk", sign.name, buf, {
lnum = linenr,
Expand Down
2 changes: 2 additions & 0 deletions lua/hunk/ui/file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function M.create(window, params)
end

local function apply_signs()
api.signs.clear_signs(buf)

for _, hunk in ipairs(params.change.hunks) do
for i in utils.hunk_lines(hunk[params.side]) do
local is_selected = params.change.selected_lines[params.side][i]
Expand Down
1 change: 1 addition & 0 deletions lua/hunk/ui/tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ function M.create(opts)

function Component.render()
tree:render()
signs.clear_signs(buf)
apply_signs(tree, buf)
end

Expand Down

0 comments on commit d79dcc0

Please sign in to comment.