From b494d05c9d12c1b0d9dfa158bd855b57b9d596d9 Mon Sep 17 00:00:00 2001 From: yetone Date: Sun, 25 Aug 2024 14:06:00 +0800 Subject: [PATCH] fix: the highlights are not set correctly (#207) --- lua/avante/highlights.lua | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/lua/avante/highlights.lua b/lua/avante/highlights.lua index debd933..3785ae7 100644 --- a/lua/avante/highlights.lua +++ b/lua/avante/highlights.lua @@ -14,39 +14,32 @@ local M = { M.input_ns = api.nvim_create_namespace("avante_input") M.hint_ns = api.nvim_create_namespace("avante_hint") +local function has_set_colors(hl_group) + local hl = api.nvim_get_hl(0, { name = hl_group }) + return next(hl) ~= nil +end + M.setup = function() local normal = api.nvim_get_hl(0, { name = "Normal" }) local normal_float = api.nvim_get_hl(0, { name = "NormalFloat" }) - local has_set_colors = {} - for _, hl_group in ipairs({ - M.TITLE, - M.REVERSED_TITLE, - M.SUBTITLE, - M.REVERSED_SUBTITLE, - M.THIRD_TITLE, - M.REVERSED_THIRD_TITLE, - }) do - has_set_colors[hl_group] = api.nvim_get_hl(0, { name = hl_group }) ~= vim.empty_dict() - end - if Config.behaviour.auto_set_highlight_group then - if not has_set_colors[M.TITLE] then + if not has_set_colors(M.TITLE) then api.nvim_set_hl(0, M.TITLE, { fg = "#1e222a", bg = "#98c379" }) end - if not has_set_colors[M.REVERSED_TITLE] then + if not has_set_colors(M.REVERSED_TITLE) then api.nvim_set_hl(0, M.REVERSED_TITLE, { fg = "#98c379" }) end - if not has_set_colors[M.SUBTITLE] then + if not has_set_colors(M.SUBTITLE) then api.nvim_set_hl(0, M.SUBTITLE, { fg = "#1e222a", bg = "#56b6c2" }) end - if not has_set_colors[M.REVERSED_SUBTITLE] then + if not has_set_colors(M.REVERSED_SUBTITLE) then api.nvim_set_hl(0, M.REVERSED_SUBTITLE, { fg = "#56b6c2" }) end - if not has_set_colors[M.THIRD_TITLE] then + if not has_set_colors(M.THIRD_TITLE) then api.nvim_set_hl(0, M.THIRD_TITLE, { fg = "#ABB2BF", bg = "#353B45" }) end - if not has_set_colors[M.REVERSED_THIRD_TITLE] then + if not has_set_colors(M.REVERSED_THIRD_TITLE) then api.nvim_set_hl(0, M.REVERSED_THIRD_TITLE, { fg = "#353B45" }) end end