diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-11-03 12:26:38 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-11-05 12:18:29 +0100 |
commit | 68cb4a7405ea9f8841d1f25ee8997c49e77fa679 (patch) | |
tree | f2766eca6c0cb9fefb9739ffc3256649ba8d4a61 /test/functional | |
parent | 92e99bb1058dd837c451675175efb8511c5f8e15 (diff) | |
download | rneovim-68cb4a7405ea9f8841d1f25ee8997c49e77fa679.tar.gz rneovim-68cb4a7405ea9f8841d1f25ee8997c49e77fa679.tar.bz2 rneovim-68cb4a7405ea9f8841d1f25ee8997c49e77fa679.zip |
feat(extmarks): add "undo_restore" flag to opt out of undo-restoring
It is a design goal of extmarks that they allow precise tracking
of changes across undo/redo, including restore the exact positions
after a do/undo or undo/redo cycle. However this behavior is not useful
for all usecases. Many plugins won't keep marks around for long after
text changes, but uses them more like a cache until some external source
(like LSP semantic highlights) has fully updated to changed text and
then will explicitly readjust/replace extmarks as needed.
Add a "undo_restore" flag which is true by default (matches existing
behavior) but can be set to false to opt-out of this behavior.
Delete dead u_extmark_set() code.
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/ui/decorations_spec.lua | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index e56f82bd9f..68c3e73e61 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -11,6 +11,7 @@ local meths = helpers.meths local funcs = helpers.funcs local curbufmeths = helpers.curbufmeths local command = helpers.command +local eq = helpers.eq local assert_alive = helpers.assert_alive describe('decorations providers', function() @@ -1997,6 +1998,60 @@ describe('extmark decorations', function() ]]} end) + local function with_undo_restore(val) + screen:try_resize(50, 5) + insert(example_text) + feed'gg' + meths.buf_set_extmark(0, ns, 0, 6, { end_col=13, hl_group = 'NonText', undo_restore=val}) + screen:expect{grid=[[ + ^for _,{1:item in} ipairs(items) do | + local text, hl_id_cell, count = unpack(item) | + if hl_id_cell ~= nil then | + hl_id = hl_id_cell | + | + ]]} + + meths.buf_set_text(0, 0, 4, 0, 8, {''}) + screen:expect{grid=[[ + ^for {1:em in} ipairs(items) do | + local text, hl_id_cell, count = unpack(item) | + if hl_id_cell ~= nil then | + hl_id = hl_id_cell | + | + ]]} + end + + it("highlights do reapply to restored text after delete", function() + with_undo_restore(true) -- also default behavior + + feed 'u' + screen:expect{grid=[[ + ^for _,{1:item in} ipairs(items) do | + local text, hl_id_cell, count = unpack(item) | + if hl_id_cell ~= nil then | + hl_id = hl_id_cell | + 1 change; before #2 0 seconds ago | + ]]} + end) + + it("highlights don't reapply to restored text after delete with no_undo_restore", function() + with_undo_restore(false) + + feed 'u' + screen:expect{grid=[[ + ^for _,it{1:em in} ipairs(items) do | + local text, hl_id_cell, count = unpack(item) | + if hl_id_cell ~= nil then | + hl_id = hl_id_cell | + 1 change; before #2 0 seconds ago | + ]]} + + eq({ { 1, 0, 8, { end_col = 13, end_right_gravity = false, end_row = 0, + hl_eol = false, hl_group = "NonText", undo_restore = false, + ns_id = 1, priority = 4096, right_gravity = true } } }, + meths.buf_get_extmarks(0, ns, {0,0}, {0, -1}, {details=true})) + end) + it('virtual text works with rightleft', function() screen:try_resize(50, 3) insert('abcdefghijklmn') |