aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2024-01-16 18:01:51 +0100
committerLewis Russell <me@lewisr.dev>2024-01-17 10:17:11 +0000
commitf871fee8b699ee6b870753ef140023e0a1f4ff23 (patch)
tree6e74d9032b35374ba5627b69dc9324add067c655
parentb3e5587b7f1cd6206240aea38740d2205c10ae34 (diff)
downloadrneovim-f871fee8b699ee6b870753ef140023e0a1f4ff23.tar.gz
rneovim-f871fee8b699ee6b870753ef140023e0a1f4ff23.tar.bz2
rneovim-f871fee8b699ee6b870753ef140023e0a1f4ff23.zip
fix(column): pass kFalse when initializing "b_signcols.count"
Problem: Wrong "clear" argument passed to buf_signcols_count_range when initializing "b_signcols.count" for the first time. Solution: Pass kFalse so that the "nested" counter is not incorrectly decremented.
-rw-r--r--src/nvim/decoration.c12
-rw-r--r--src/nvim/drawscreen.c2
-rw-r--r--test/functional/ui/sign_spec.lua9
3 files changed, 16 insertions, 7 deletions
diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c
index ddc4708740..7cce6b3ad1 100644
--- a/src/nvim/decoration.c
+++ b/src/nvim/decoration.c
@@ -840,14 +840,14 @@ void buf_signcols_count_range(buf_T *buf, int row1, int row2, int add, TriState
// For each row increment "b_signcols.count" at the number of counted signs,
// and decrement at the previous number of signs. These two operations are
- // split in separate calls if "clear" is not kNone (surrounding a marktree splice).
+ // split in separate calls if "clear" is not kFalse (surrounding a marktree splice).
for (int i = 0; i < row2 + 1 - row1; i++) {
- int width = MIN(SIGN_SHOW_MAX, count[i] - add);
- if (clear != kNone && width > 0) {
- buf->b_signcols.count[width - 1]--;
- assert(buf->b_signcols.count[width - 1] >= 0);
+ int prevwidth = MIN(SIGN_SHOW_MAX, count[i] - add);
+ if (clear != kNone && prevwidth > 0) {
+ buf->b_signcols.count[prevwidth - 1]--;
+ assert(buf->b_signcols.count[prevwidth - 1] >= 0);
}
- width = MIN(SIGN_SHOW_MAX, count[i]);
+ int width = MIN(SIGN_SHOW_MAX, count[i]);
if (clear != kTrue && width > 0) {
buf->b_signcols.count[width - 1]++;
if (width > buf->b_signcols.max) {
diff --git a/src/nvim/drawscreen.c b/src/nvim/drawscreen.c
index 8341989ab0..9a3fffde07 100644
--- a/src/nvim/drawscreen.c
+++ b/src/nvim/drawscreen.c
@@ -1206,7 +1206,7 @@ static bool win_redraw_signcols(win_T *wp)
if (!buf->b_signcols.autom
&& (*wp->w_p_stc != NUL || (wp->w_maxscwidth > 1 && wp->w_minscwidth != wp->w_maxscwidth))) {
buf->b_signcols.autom = true;
- buf_signcols_count_range(buf, 0, buf->b_ml.ml_line_count, MAXLNUM, kNone);
+ buf_signcols_count_range(buf, 0, buf->b_ml.ml_line_count, MAXLNUM, kFalse);
}
while (buf->b_signcols.max > 0 && buf->b_signcols.count[buf->b_signcols.max - 1] == 0) {
diff --git a/test/functional/ui/sign_spec.lua b/test/functional/ui/sign_spec.lua
index 5e45c3113b..29ec08e15c 100644
--- a/test/functional/ui/sign_spec.lua
+++ b/test/functional/ui/sign_spec.lua
@@ -539,4 +539,13 @@ describe('Signs', function()
|
]])
end)
+
+ it('no negative b_signcols.count with undo after initializing', function()
+ exec([[
+ set signcolumn=auto:2
+ call setline(1, 'a')
+ call nvim_buf_set_extmark(0, nvim_create_namespace(''), 0, 0, {'sign_text':'S1'})
+ delete | redraw | undo
+ ]])
+ end)
end)