From d79dcc0e050ce1f9598f3f44ced380f426e249d2 Mon Sep 17 00:00:00 2001 From: Julien Vincent Date: Wed, 24 Jul 2024 10:55:38 +0100 Subject: [PATCH] Clear all old signs before reapplying 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 --- lua/hunk/api/signs.lua | 6 ++++++ lua/hunk/ui/file.lua | 2 ++ lua/hunk/ui/tree.lua | 1 + 3 files changed, 9 insertions(+) diff --git a/lua/hunk/api/signs.lua b/lua/hunk/api/signs.lua index e9e397f..65ea559 100644 --- a/lua/hunk/api/signs.lua +++ b/lua/hunk/api/signs.lua @@ -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, diff --git a/lua/hunk/ui/file.lua b/lua/hunk/ui/file.lua index 5d9be43..12dc909 100644 --- a/lua/hunk/ui/file.lua +++ b/lua/hunk/ui/file.lua @@ -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] diff --git a/lua/hunk/ui/tree.lua b/lua/hunk/ui/tree.lua index 74ff242..27535c0 100644 --- a/lua/hunk/ui/tree.lua +++ b/lua/hunk/ui/tree.lua @@ -218,6 +218,7 @@ function M.create(opts) function Component.render() tree:render() + signs.clear_signs(buf) apply_signs(tree, buf) end