diff options
author | Luuk van Baal <luukvbaal@gmail.com> | 2024-01-11 14:30:12 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-01-15 09:37:53 +0000 |
commit | 967c7abde3c6fa3210a4920a5848a54dc913d851 (patch) | |
tree | a44518ccfcfab9a0011f05f62aa0be543fd8a3e2 /test/functional/ui/decorations_spec.lua | |
parent | 4d91604c8868b7afaf429cc16b72192ce89ea698 (diff) | |
download | rneovim-967c7abde3c6fa3210a4920a5848a54dc913d851.tar.gz rneovim-967c7abde3c6fa3210a4920a5848a54dc913d851.tar.bz2 rneovim-967c7abde3c6fa3210a4920a5848a54dc913d851.zip |
fix(column): keep track of number of lines with number of signs
Problem: Some edge cases to the old (pre-#26406) and current "b_signcols"
structure result in an incorrectly sized "auto" 'signcolumn'.
Solution: * Implement a simpler 'signcolumn' validation strategy by immediately
counting the number of signs in a range upon sign insertion and
deletion. Decrease in performance here but there is a clear path
forward to decreasing this performance hit by moving signs to a
dedicated marktree, or by adding meta-data to the existing
marktree which may be queried more efficiently?
* Also replace "max_count" and keep track of the number of lines with
a certain number of signs. This makes it so that it is no longer
necessary to scan the entire buffer when the maximum number of signs
decreases. This likely makes the commit a net increase in performance.
* To ensure correctness we also have re-initialize the count for an
edited region that spans multiple lines. Such an edit may move the
signs within it. Thus we count and decrement before splicing the
marktree and count and increment after.
Diffstat (limited to 'test/functional/ui/decorations_spec.lua')
-rw-r--r-- | test/functional/ui/decorations_spec.lua | 99 |
1 files changed, 94 insertions, 5 deletions
diff --git a/test/functional/ui/decorations_spec.lua b/test/functional/ui/decorations_spec.lua index 186bf19214..0844ddf249 100644 --- a/test/functional/ui/decorations_spec.lua +++ b/test/functional/ui/decorations_spec.lua @@ -4898,14 +4898,103 @@ l5 it('correct width with multiple overlapping signs', function() screen:try_resize(20, 4) insert(example_test3) - api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1', end_row=2}) - api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S2', end_row=2}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S1'}) + api.nvim_buf_set_extmark(0, ns, 0, -1, {sign_text='S2', end_row=2}) + api.nvim_buf_set_extmark(0, ns, 1, -1, {sign_text='S3', end_row=2}) feed('gg') + local s1 = [[ + S1S2^l1 | + S2S3l2 | + S2S3l3 | + | + ]] + screen:expect{grid=s1} + -- Correct width when :move'ing a line with signs + command('move2') + screen:expect{grid=[[ + S3{1: }l2 | + S1S2S3^l1 | + {1: }l3 | + | + ]]} + command('silent undo') + screen:expect{grid=s1} + command('d') + screen:expect{grid=[[ + S1S2S3^l2 | + S2S3{1: }l3 | + {1: }l4 | + | + ]]} + command('d') + screen:expect{grid=[[ + S1S2S3^l3 | + {1: }l4 | + {1: }l5 | + | + ]]} + end) + + it('correct width when adding and removing multiple signs', function() + screen:try_resize(20, 4) + insert(example_test3) + feed('gg') + command([[ + let ns = nvim_create_namespace('') + call nvim_buf_set_extmark(0, ns, 0, 0, {'sign_text':'S1', 'end_row':3}) + let s1 = nvim_buf_set_extmark(0, ns, 2, 0, {'sign_text':'S2', 'end_row':4}) + let s2 = nvim_buf_set_extmark(0, ns, 5, 0, {'sign_text':'S3'}) + let s3 = nvim_buf_set_extmark(0, ns, 6, 0, {'sign_text':'S3'}) + let s4 = nvim_buf_set_extmark(0, ns, 5, 0, {'sign_text':'S3'}) + let s5 = nvim_buf_set_extmark(0, ns, 6, 0, {'sign_text':'S3'}) + redraw! + call nvim_buf_del_extmark(0, ns, s2) + call nvim_buf_del_extmark(0, ns, s3) + call nvim_buf_del_extmark(0, ns, s4) + call nvim_buf_del_extmark(0, ns, s5) + redraw! + call nvim_buf_del_extmark(0, ns, s1) + ]]) screen:expect{grid=[[ - S1{1: }^l1 | - S1S2l2 | - S1S2l3 | + S1^l1 | + S1l2 | + S1l3 | + | + ]]} + end) + + it('correct width when deleting lines', function() + screen:try_resize(20, 4) + insert(example_test3) + feed('gg') + command([[ + let ns = nvim_create_namespace('') + call nvim_buf_set_extmark(0, ns, 4, 0, {'sign_text':'S1'}) + call nvim_buf_set_extmark(0, ns, 4, 0, {'sign_text':'S2'}) + let s3 = nvim_buf_set_extmark(0, ns, 5, 0, {'sign_text':'S3'}) + call nvim_buf_del_extmark(0, ns, s3) + norm 4Gdd + ]]) + screen:expect{grid=[[ + {1: }l3 | + S1S2l5 | + {1: }^ | + | + ]]} + end) + + it('correct width when splitting lines with signs on different columns', function() + screen:try_resize(20, 4) + insert(example_test3) + feed('gg') + api.nvim_buf_set_extmark(0, ns, 0, 0, {sign_text='S1'}) + api.nvim_buf_set_extmark(0, ns, 0, 1, {sign_text='S2'}) + feed('a<cr><esc>') + screen:expect{grid=[[ + S1l | + S2^1 | + {1: }l2 | | ]]} end) |