Skip to content

Commit

Permalink
fix: preserve PrecognitionHighlight through colorscheme changes (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
TymekDev authored Oct 29, 2024
1 parent 35c402c commit 19d9706
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 10 additions & 2 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ function M.toggle()
return visible
end

local function setup_highlights()
vim.api.nvim_set_hl(0, "PrecognitionHighlight", config.highlightColor)
end

---@param opts Precognition.PartialConfig
function M.setup(opts)
opts = opts or {}
Expand All @@ -450,8 +454,12 @@ function M.setup(opts)
ns = vim.api.nvim_create_namespace("precognition")
au = vim.api.nvim_create_augroup("precognition", { clear = true })

local hl_name = "PrecognitionHighlight"
vim.api.nvim_set_hl(0, hl_name, config.highlightColor)
setup_highlights()
vim.api.nvim_create_autocmd("ColorScheme", {
desc = "Set precognition.nvim's highlights up",
group = au,
callback = setup_highlights,
})

create_command()

Expand Down
10 changes: 8 additions & 2 deletions tests/precognition/e2e_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ describe("e2e tests", function()

it("auto commands are set", function()
local autocmds = vim.api.nvim_get_autocmds({ group = "precognition" })
eq(4, vim.tbl_count(autocmds))
eq(5, vim.tbl_count(autocmds))
precognition.peek()
autocmds = vim.api.nvim_get_autocmds({ group = "precognition" })
eq(7, vim.tbl_count(autocmds))
eq(8, vim.tbl_count(autocmds))
end)

-- it("namespace is created", function()
Expand Down Expand Up @@ -223,6 +223,12 @@ describe("e2e tests", function()
eq("PrecognitionHighlight", extmarks[3].virt_lines[1][1][2])
eq(customMark, vim.api.nvim_get_hl(0, { name = extmarks[3].virt_lines[1][1][2] }))
end)

it("preserves highlight groups through a colorscheme change", function()
vim.cmd.colorscheme("default")
local hl = vim.api.nvim_get_hl(0, { name = "PrecognitionHighlight" })
eq(false, vim.tbl_isempty(hl))
end)
end)

describe("Gutter Priority", function()
Expand Down

0 comments on commit 19d9706

Please sign in to comment.