diff options
author | akianonymus <anonymus.aki@gmail.com> | 2023-02-25 23:26:18 +0530 |
---|---|---|
committer | Akshay <anonymus.aki@gmail.com> | 2023-02-26 11:10:37 +0530 |
commit | 1f59884e0d6b3f84e966393196da51abc4a97fa2 (patch) | |
tree | 7e7acf346432fe98234172fc93c8aa10ee93f910 /lua/colorizer.lua | |
parent | fix: Improve individual opts behaviour | #48 (diff) |
fix: Highlight buffer even if not focused | #28
like cmp comletion menu
Diffstat (limited to 'lua/colorizer.lua')
-rw-r--r-- | lua/colorizer.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lua/colorizer.lua b/lua/colorizer.lua index 8da9ce0..f7c189f 100644 --- a/lua/colorizer.lua +++ b/lua/colorizer.lua @@ -90,6 +90,8 @@ local AUGROUP_NAME = "ColorizerSetup" local BUFFER_OPTIONS = {} -- buffer local options created after setup local BUFFER_LOCAL = {} +-- the current buffer id, used in buf_attach calls +local CURRENT_BUF = 0 ---defaults options. --In `user_default_options`, there are 2 types of options @@ -358,10 +360,38 @@ function colorizer.attach_to_buffer(buf, options, typ) table.insert(text_changed_au, "InsertLeave") end + if CURRENT_BUF == 0 then + CURRENT_BUF = buf + end + + -- attach using lua api so buffer gets updated even when not the current buffer + -- completely moving to buf_attach is not possible because it doesn't handle all the text change events + vim.api.nvim_buf_attach(buf, false, { + on_lines = function(_, buffer) + -- only reload if the buffer is not the current one + if not (CURRENT_BUF == buffer) then + -- only reload if it was not disabled using detach_from_buffer + if BUFFER_OPTIONS[buf] then + rehighlight_buffer(buf, options, BUFFER_LOCAL[buf]) + end + end + end, + on_reload = function(_, buffer) + -- only reload if the buffer is not the current one + if not (CURRENT_BUF == buffer) then + -- only reload if it was not disabled using detach_from_buffer + if BUFFER_OPTIONS[buf] then + rehighlight_buffer(buf, options, BUFFER_LOCAL[buf]) + end + end + end, + }) + autocmds[#autocmds + 1] = autocmd(text_changed_au, { group = au_group_id, buffer = buf, callback = function(args) + CURRENT_BUF = buf -- only reload if it was not disabled using detach_from_buffer if BUFFER_OPTIONS[buf] then BUFFER_LOCAL[buf].__event = args.event |