From 953607cac7d923a3bf8608af372d2a30466efa7e Mon Sep 17 00:00:00 2001 From: Breno Prata Date: Fri, 24 May 2024 22:45:49 +0200 Subject: [PATCH 1/3] #93 - Fix extmark highlight on BufEnter --- lua/nvim-highlight-colors/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-highlight-colors/init.lua b/lua/nvim-highlight-colors/init.lua index 67756a2..7e5d6c6 100644 --- a/lua/nvim-highlight-colors/init.lua +++ b/lua/nvim-highlight-colors/init.lua @@ -188,6 +188,7 @@ vim.api.nvim_create_autocmd({ "TextChangedI", "TextChangedP", "LspAttach", + "BufEnter", }, { callback = M.handle_change_autocmd_callback, }) @@ -195,7 +196,6 @@ vim.api.nvim_create_autocmd({ vim.api.nvim_create_autocmd({ "VimResized", "WinScrolled", - "BufEnter", }, { callback = M.handle_autocmd_callback, }) From 2a7a6da935e5f6493076adbeaa0401e1b0aff950 Mon Sep 17 00:00:00 2001 From: Breno Prata Date: Sat, 25 May 2024 13:40:43 +0200 Subject: [PATCH 2/3] #93 - Fix extmark highlight on scroll --- lua/nvim-highlight-colors/utils.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lua/nvim-highlight-colors/utils.lua b/lua/nvim-highlight-colors/utils.lua index 044d488..dd72bbe 100644 --- a/lua/nvim-highlight-colors/utils.lua +++ b/lua/nvim-highlight-colors/utils.lua @@ -89,12 +89,17 @@ end function M.highlight_extmarks(active_buffer_id, ns_id, data, highlight_group, options) local start_extmark_row = data.row + 1 local start_extmark_column = data.start_column - 1 - local end_extmark_column = data.end_column - 1 + local virtual_text_position = M.get_virtual_text_position(options) + local virtual_text_column = M.get_virtual_text_column( + virtual_text_position, + start_extmark_column, + data.end_column + ) local already_highlighted_extmark = vim.api.nvim_buf_get_extmarks( active_buffer_id, ns_id, {start_extmark_row, start_extmark_column}, - {start_extmark_row, end_extmark_column}, + {start_extmark_row, virtual_text_column}, {details = true} ) local is_already_highlighted = #table_utils.filter( @@ -119,13 +124,6 @@ function M.highlight_extmarks(active_buffer_id, ns_id, data, highlight_group, op ) end - - local virtual_text_position = M.get_virtual_text_position(options) - local virtual_text_column = M.get_virtual_text_column( - virtual_text_position, - start_extmark_column, - data.end_column - ) vim.api.nvim_buf_set_extmark( active_buffer_id, ns_id, From 582064092cff170331064b7d198a5b97cb261fca Mon Sep 17 00:00:00 2001 From: Breno Prata Date: Sat, 25 May 2024 15:10:57 +0200 Subject: [PATCH 3/3] #90 - Check if buffer is valid before running highlight logic --- lua/nvim-highlight-colors/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-highlight-colors/init.lua b/lua/nvim-highlight-colors/init.lua index 7e5d6c6..8b41e4c 100644 --- a/lua/nvim-highlight-colors/init.lua +++ b/lua/nvim-highlight-colors/init.lua @@ -110,7 +110,7 @@ end function M.refresh_highlights(active_buffer_id, should_clear_highlights) local buffer_id = active_buffer_id ~= nil and active_buffer_id or 0 - if vim.bo[buffer_id].buftype == "terminal" then + if not vim.api.nvim_buf_is_valid(active_buffer_id) or vim.bo[buffer_id].buftype == "terminal" then return end