@@ -11,24 +11,6 @@ local util = require("notify.util")
11
11
--- @field _config table
12
12
local NotifyBufHighlights = {}
13
13
14
- local function manual_get_hl (name )
15
- local synID = vim .fn .synIDtrans (vim .fn .hlID (name ))
16
- local result = {
17
- foreground = tonumber (vim .fn .synIDattr (synID , " fg" ):gsub (" #" , " " ), 16 ),
18
- background = tonumber (vim .fn .synIDattr (synID , " bg" ):gsub (" #" , " " ), 16 ),
19
- }
20
- return result
21
- end
22
-
23
- local function get_hl (name )
24
- local definition = vim .api .nvim_get_hl_by_name (name , true )
25
- if definition [true ] then
26
- -- https://github.com/neovim/neovim/issues/18024
27
- return manual_get_hl (name )
28
- end
29
- return definition
30
- end
31
-
32
14
function NotifyBufHighlights :new (level , buffer , config )
33
15
local function linked_group (section )
34
16
local orig = " Notify" .. level .. section
@@ -38,8 +20,11 @@ function NotifyBufHighlights:new(level, buffer, config)
38
20
local new = orig .. buffer
39
21
40
22
vim .api .nvim_set_hl (0 , new , { link = orig })
23
+ local hl = vim .api .nvim_get_hl (0 , { name = orig , create = false , link = false })
24
+ -- Removes the unwanted 'default' key, as we will copy the table for updating the highlight later.
25
+ hl .default = nil
41
26
42
- return new , get_hl ( new )
27
+ return new , hl
43
28
end
44
29
45
30
local title , title_def = linked_group (" Title" )
@@ -83,7 +68,7 @@ function NotifyBufHighlights:_redefine_treesitter()
83
68
return new
84
69
end
85
70
vim .api .nvim_set_hl (0 , new , { link = orig })
86
- self .groups [new ] = get_hl ( new )
71
+ self .groups [new ] = vim . api . nvim_get_hl ( 0 , { name = new , link = false } )
87
72
return new
88
73
end
89
74
@@ -150,31 +135,30 @@ end
150
135
function NotifyBufHighlights :set_opacity (alpha )
151
136
if
152
137
not self ._treesitter_redefined
153
- and vim .api .nvim_buf_get_option ( self .buffer , " filetype " ) ~= " notify"
138
+ and vim .api .nvim_get_option_value ( " filetype " , { buf = self .buffer } ) ~= " notify"
154
139
then
155
140
self :_redefine_treesitter ()
156
141
end
157
142
self .opacity = alpha
158
143
local background = self ._config .background_colour ()
144
+ local updated = false
159
145
for group , fields in pairs (self .groups ) do
160
- local updated_fields = {}
161
- vim .api .nvim_set_hl (0 , group , updated_fields )
162
- local hl_string = " "
163
- if fields .foreground then
164
- hl_string = " guifg=#"
165
- .. string.format (" %06x" , util .blend (fields .foreground , background , alpha / 100 ))
146
+ local fg = fields .fg
147
+ if fg then
148
+ fg = util .blend (fg , background , alpha / 100 )
166
149
end
167
- if fields .background then
168
- hl_string = hl_string
169
- .. " guibg=#"
170
- .. string.format (" %06x" , util .blend (fields .background , background , alpha / 100 ))
150
+ local bg = fields .bg
151
+ if bg then
152
+ bg = util .blend (bg , background , alpha / 100 )
171
153
end
172
154
173
- if hl_string ~= " " then
174
- -- Can't use nvim_set_hl https://github.com/neovim/neovim/issues/18160
175
- vim .cmd (" hi " .. group .. " " .. hl_string )
155
+ if fg ~= fields .fg or bg ~= fields .bg then
156
+ local hl = vim .tbl_extend (' force' , fields , { fg = fg , bg = bg })
157
+ vim .api .nvim_set_hl (0 , group , hl )
158
+ updated = true
176
159
end
177
160
end
161
+ return updated
178
162
end
179
163
180
164
function NotifyBufHighlights :get_opacity ()
0 commit comments