commit d6653e1cc957ef39b397e073230da87ee9a5411d
parent 5ff8a2fa8bd1644813c16d797d9101fece714365
Author: luukvbaal <luukvbaal@gmail.com>
Date: Wed, 19 Mar 2025 11:00:42 +0100
fix(marks): ensure decor is removed with proper range (#32973)
Problem: Paired mark whose end is in front of its start should not have
its decor removed (as fixed by 72f630f9), but may still need to
have its range redrawn.
Solution: Still call `buf_decor_remove()` but ensure it is not called with
an inverse range when `extmark_del()` is called on an end mark.
Diffstat:
2 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/src/nvim/extmark.c b/src/nvim/extmark.c
@@ -180,11 +180,14 @@ void extmark_del(buf_T *buf, MarkTreeIter *itr, MTKey key, bool restore)
}
if (mt_decor_any(key)) {
- // If key is an end mark it has been found first while iterating the marktree,
- // indicating the decor is already invalid.
- if (mt_invalid(key) || mt_end(key)) {
+ if (mt_invalid(key)) {
decor_free(mt_decor(key));
} else {
+ if (mt_end(key)) {
+ MTKey k = key;
+ key = key2;
+ key2 = k;
+ }
buf_decor_remove(buf, key.pos.row, key2.pos.row, key.pos.col, mt_decor(key), true);
}
}
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua
@@ -6393,24 +6393,19 @@ l5
end)
describe('decorations: virt_text', function()
- local screen ---@type test.functional.ui.screen
+ local ns, screen ---@type integer, test.functional.ui.screen
before_each(function()
clear()
screen = Screen.new(50, 10)
+ ns = api.nvim_create_namespace('test')
end)
it('avoids regression in #17638', function()
- exec_lua[[
- vim.wo.number = true
- vim.wo.relativenumber = true
- ]]
-
+ command 'set number relativenumber'
command 'normal 4ohello'
command 'normal aVIRTUAL'
- local ns = api.nvim_create_namespace('test')
-
api.nvim_buf_set_extmark(0, ns, 2, 0, {
virt_text = {{"hello", "String"}},
virt_text_win_col = 20,
@@ -6451,7 +6446,6 @@ describe('decorations: virt_text', function()
|
]]}
- local ns = api.nvim_create_namespace('ns')
for row = 1, 5 do
api.nvim_buf_set_extmark(0, ns, row, 0, { id = 1, virt_text = {{'world', 'Normal'}} })
end
@@ -6464,6 +6458,30 @@ describe('decorations: virt_text', function()
|
]]}
end)
+
+ it('redraws correctly when removing mark whose end ends up in front of start', function()
+ command('normal 5ohello')
+ api.nvim_buf_set_extmark(0, ns, 2, 0, { end_col = 1, virt_text = {{'world', 'Normal'}} })
+ screen:expect([[
+ |
+ hello |
+ hello world |
+ hello |*2
+ hell^o |
+ {1:~ }|*3
+ |
+ ]])
+ feed('3Gdd')
+ api.nvim_buf_clear_namespace(0, ns, 0, -1)
+ screen:expect([[
+ |
+ hello |
+ ^hello |
+ hello |*2
+ {1:~ }|*4
+ |
+ ]])
+ end)
end)
describe('decorations: window scoped', function()