gitsigns.nvim icon indicating copy to clipboard operation
gitsigns.nvim copied to clipboard

toggle_line_hl will shadow those extmarks added by toggle_word_diff

Open xzbdmw opened this issue 1 year ago • 1 comments

Description

As the title says, After running toggle_word_diff and then toggle_line_hl, word_diff highlight get shadowed by line_hl, after running toggle_line_hl again, word_diff highlight reappears.

Neovim version

0.10

Operating system and version

macos 14

Expected behavior

word diff highlight and line_hl exist together, and word diff have higher priority.

Actual behavior

word_diff highlight get cleared.

Minimal config

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
  -- ADD OTHER PLUGINS _NECESSARY_ TO REPRODUCE THE ISSUE
} do
local install_path = vim.fn.fnamemodify('gitsigns_issue/'..name, ':p')
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
end
vim.opt.runtimepath:append(install_path)
end

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages
  -- ADD GITSIGNS CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE
}

-- ADD INIT.LUA SETTINGS THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE

Steps to reproduce

At first I thought it is a priority problem, but with this simple snippet, result is the same.

keymap = vim.keymap.set
api = vim.api
local function has_namespace(name_space)
    local ns = api.nvim_create_namespace(name_space)
    local extmark = api.nvim_buf_get_extmarks(0, ns, { 0, 0 }, { -1, -1 }, {})
    return extmark ~= nil and #extmark ~= 0
end
keymap("n", "<leader>yY", function()
    local cur_line = api.nvim_win_get_cursor(0)[1]
    if has_namespace("line") then
        api.nvim_buf_clear_namespace(0, api.nvim_create_namespace("line"), 0, -1)
    else
        local ns = vim.api.nvim_create_namespace("line")
        api.nvim_buf_set_extmark(0, ns, cur_line - 1, -1, {
            line_hl_group = "GitSignsAddLnInline",
            priority = 3,
        })
    end
end)
keymap("n", "<leader>yy", function()
    local cur_line, cur_col = unpack(api.nvim_win_get_cursor(0))
    if has_namespace("char") then
        api.nvim_buf_clear_namespace(0, api.nvim_create_namespace("char"), 0, -1)
    else
        local ns = vim.api.nvim_create_namespace("char")
        api.nvim_buf_set_extmark(0, ns, cur_line - 1, cur_col, {
            end_col = cur_col + 5,
            hl_group = "GitSignsDeleteVirtLnInLine",
            priority = 1000,
        })
    end
end)

first type <leader>yy, red color appears, then <leader>yY, entire line get the same color as GitSignsAddLnInline, then <leader>yY again, red color reappears.

Gitsigns debug messages

No response

Gitsigns cache

No response

xzbdmw avatar Aug 29 '24 23:08 xzbdmw

It seems I can simulate

        api.nvim_buf_set_extmark(0, ns, cur_line - 1, -1, {
            line_hl_group = "GitSignsAddLnInline",
            priority = 3,
        })

with

        api.nvim_buf_set_extmark(0, ns, cur_line - 1, 0, {
            end_line = cur_line,
            hl_group = "GitSignsAddLnInline",
            priority = 3,
            end_col = 0,
            hl_eol = true,
            strict = false,
        })

which does not have above shortcomings.

xzbdmw avatar Aug 30 '24 00:08 xzbdmw

The above doesn't work because having end_row set to the next line will cause an additional sign in the sign column. So the only way to implement this would be to add a separate extmark.

Since this is arguably a bug in Neovim core, I don't think this is worth fixing here.

lewis6991 avatar Jan 20 '25 11:01 lewis6991