Skip to content

Commit

Permalink
fix(nvim): remove the underline from diff view
Browse files Browse the repository at this point in the history
  • Loading branch information
Alienover committed Jun 10, 2023
1 parent 37a65aa commit 2e49184
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
49 changes: 49 additions & 0 deletions dotfiles/.config/nvim/lua/autocmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local groups = {
filetype = vim.api.nvim_create_augroup("FT", { clear = true }),
folding = vim.api.nvim_create_augroup("Folding", { clear = true }),
terminal = vim.api.nvim_create_augroup("Terminal", { clear = true }),
diffview = vim.api.nvim_create_augroup("DiffView", { clear = true }),
}

vim.api.nvim_create_autocmd("TermEnter", {
Expand Down Expand Up @@ -79,3 +80,51 @@ vim.api.nvim_create_autocmd("FileType", {
vim.wo.conceallevel = 2
end,
})

vim.api.nvim_create_autocmd("BufEnter", {
-- INFO: Work around https://github.com/neovim/neovim/issues/9800
desc = "Remove the underline in diff view",

group = groups.diffview,
pattern = "*",
callback = function()
local hl_name = "CursorLine"

local set_cursor_hl = function(cursor_hl, opts)
vim.F.npcall(
vim.api.nvim_set_hl,
0,
hl_name,
vim.tbl_deep_extend("force", cursor_hl or {}, opts or {})
)
end

local get_cursor_hl = function()
local rgb_hl = {}
local hl = vim.F.npcall(vim.api.nvim_get_hl, 0, { name = hl_name })

if hl then
for _, key in ipairs({ "fg", "bg" }) do
local color = hl[key]
rgb_hl[key] = color and string.format("#%06x", color) or nil
end
end

return rgb_hl
end

if vim.opt.diff:get() then
if not vim.g.__cursor_hl then
vim.g.__cursor_hl = get_cursor_hl()

set_cursor_hl(vim.g.__cursor_hl, { ctermfg = "white" })
end
else
if vim.g.__cursor_hl then
set_cursor_hl(vim.g.__cursor_hl)
end

vim.g.__cursor_hl = nil
end
end,
})
3 changes: 0 additions & 3 deletions dotfiles/.config/nvim/lua/config/catppuccin-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ local config = {

TabLineSel = { bg = colors.red },

-- INFO: Work around https://github.com/neovim/neovim/issues/9800
CursorLine = { ctermfg = "White" },

["@neorg.tags.ranged_verbatim.code_block"] = { bg = colors.surface0 },

SagaBorder = { fg = colors.surface1 },
Expand Down

0 comments on commit 2e49184

Please sign in to comment.