lukas-reineke / indent-blankline.nvim

Indent guides for Neovim
MIT License
4.16k stars 102 forks source link

Cursor color weird behavior with onedarkpro theme + indent-blankline #837

Closed yangrq1018 closed 8 months ago

yangrq1018 commented 8 months ago

Problem

The onedarkpro theme has special treatment to indent highlight groups

function M.groups(theme)
    return {
        -- https://github.com/lukas-reineke/indent-blankline.nvim/blob/caf7f61e94525bbd97e32f118efd6c0722430616/doc/indent_blankline.txt#L31
        IndentLine = { fg = theme.generated.indentline },
        IndentBlanklineChar = { link = "IndentLine" },
        IndentBlanklineSpaceChar = { link = "IndentLine" },
        IndentBlanklineSpaceCharBlankline = { link = "IndentLine" },
        IndentBlanklineContextChar = { fg = theme.palette.purple },
        IndentBlanklineContextStart = { underline = true },

        -- for Version 3.0
        IblIndent = { link = "IndentLine" },
    }
end

With this, my cursor looks like image When cursor is overlayed on top of the indent, the color is changed image

I have read Issue #346. I think this is a bug, the cursor color (bg and fg) should be consistent whether or not it's on the indent character (it's already consistent on other characters like whitespaces and keywords).

NOTE: I tried to comment out the line IblIndent = { link = "IndentLine" } in theme, clean and regenerate onedarkpro colorscheme cache, reopen the file, then the bug is gone, see image

I did some investigation with :Telescope highlights. It seems the bug is caused by linking iblIndent to the IndentLine group in theme, remove the link and set colors for iblIndent directly then it's correct.

Steps to reproduce

indent-blankline config:

local api = vim.api

local exclude_ft = { "help", "git", "markdown", "snippets", "text", "gitconfig", "alpha", "dashboard" }

require("ibl").setup {
  indent = {
    -- -- U+2502 may also be a good choice, it will be on the middle of cursor.
    -- -- U+250A is also a good choice
    char = "▏",
    -- char = "\u{2502}",
  },
  scope = {
    enabled = false,
    show_start = false,
    show_end = false,
  },
  exclude = {
    filetypes = exclude_ft,
    buftypes = { "terminal" },
  },
}

local gid = api.nvim_create_augroup("indent_blankline", { clear = true })
api.nvim_create_autocmd("InsertEnter", {
  pattern = "*",
  group = gid,
  command = "IBLDisable",
})

api.nvim_create_autocmd("InsertLeave", {
  pattern = "*",
  group = gid,
  callback = function()
    if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then
      vim.cmd([[IBLEnable]])
    end
  end,
})

Cursor config:

set guicursor=n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor20
highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black
highlight Cursor2 guifg=red guibg=red

Expected behavior

Expect the cursor to be displayed as set by highlight Cursor ... when on top of the indent.

Neovim version (nvim -v)

NVIM v0.10.0-dev-2063+ga767c046f Build type: RelWithDebInfo LuaJIT 2.1.1703358377

lukas-reineke commented 8 months ago

Like I said in #346, this is not an issue in indent-blankline. How your cursor looks depends on your terminal, and the cursor and color scheme in Neovim.

yangrq1018 commented 8 months ago

You're right, it's probably a theme issue.