From da1caaf70a15a50ad4240d25944ea59602bba771 Mon Sep 17 00:00:00 2001 From: Son Pham-Ba Date: Tue, 3 Dec 2024 12:10:28 +0100 Subject: [PATCH] fix: always remove extmarks to prevent flickering --- lua/smear_cursor/config.lua | 2 +- lua/smear_cursor/draw.lua | 5 +++-- tests/test_draw_quad.lua | 12 ++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lua/smear_cursor/config.lua b/lua/smear_cursor/config.lua index a137a6e..24163ea 100644 --- a/lua/smear_cursor/config.lua +++ b/lua/smear_cursor/config.lua @@ -40,7 +40,7 @@ M.min_slope_vertical = 2 M.color_levels = 16 -- Minimum 1 M.gamma = 2.2 -- For color blending -M.max_shade_no_matrix = 0.9 -- 0: more overhangs, 1: more matrices +M.max_shade_no_matrix = 0.75 -- 0: more overhangs, 1: more matrices M.matrix_pixel_threshold = 0.5 -- 0: all pixels, 1: no pixel M.matrix_pixel_min_factor = 0.5 -- 0: all pixels, 1: no pixel M.volume_reduction_exponent = 0.3 -- 0: no reduction, 1: full reduction diff --git a/lua/smear_cursor/draw.lua b/lua/smear_cursor/draw.lua index 5955886..fb887e2 100644 --- a/lua/smear_cursor/draw.lua +++ b/lua/smear_cursor/draw.lua @@ -116,10 +116,10 @@ M.clear = function() local wb = tab_windows.windows[i] if wb and vim.api.nvim_win_is_valid(wb.window_id) then + vim.api.nvim_buf_del_extmark(wb.buffer_id, cursor_namespace, extmark_id) if can_hide then vim.api.nvim_win_set_config(wb.window_id, { hide = true }) else - vim.api.nvim_buf_del_extmark(wb.buffer_id, cursor_namespace, extmark_id) vim.api.nvim_win_set_config(wb.window_id, { relative = "editor", row = 0, col = 0 }) end end @@ -401,7 +401,8 @@ M.draw_quad = function(corners, target_position) -- Draw shifted block if is_vertically_shifted and is_horizontally_shifted then if vertical_shade < config.max_shade_no_matrix and horizontal_shade < config.max_shade_no_matrix then - goto continue + is_horizontally_shifted = false + is_vertically_shifted = false elseif vertical_shade < horizontal_shade then is_horizontally_shifted = false else diff --git a/tests/test_draw_quad.lua b/tests/test_draw_quad.lua index d57d21f..df8edbd 100644 --- a/tests/test_draw_quad.lua +++ b/tests/test_draw_quad.lua @@ -102,6 +102,18 @@ draw.draw_quad({ { row + 5, col + 4 }, }) +-- Degenerate quads (aligned points) + +row = 14 +col = 23 + +draw.draw_quad({ + { row, col }, + { row - 1, col + 2 }, + { row + 3, col + 2 }, + { row + 3, col - 1 }, +}) + -- Lines row = 23