aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/option.c4
-rw-r--r--src/nvim/optionstr.c1
-rw-r--r--test/functional/ui/statuscolumn_spec.lua38
3 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index be82cf22c7..5ad2929a91 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -2176,6 +2176,10 @@ static char *set_bool_option(const int opt_idx, char *const varp, const int valu
if (curwin->w_p_spell) {
errmsg = did_set_spelllang(curwin);
}
+ } else if ((int *)varp == &curwin->w_p_nu && *curwin->w_p_stc != NUL) {
+ // When 'statuscolumn' is set and 'number' is changed:
+ curwin->w_nrwidth_line_count = 0; // make sure width is reset
+ curwin->w_statuscol_line_count = 0; // make sure width is re-estimated
}
if ((int *)varp == &curwin->w_p_arab) {
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index f903ad3d09..b335e255a4 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -1199,6 +1199,7 @@ static void did_set_statusline(win_T *win, char **varp, char **gvarp, char **err
ru_wid = 0;
} else if (varp == &win->w_p_stc) {
win->w_nrwidth_line_count = 0;
+ win->w_statuscol_line_count = 0;
}
char *s = *varp;
if (varp == &p_ruf && *s == '%') {
diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua
index 08b5d1913b..dfbdbb4898 100644
--- a/test/functional/ui/statuscolumn_spec.lua
+++ b/test/functional/ui/statuscolumn_spec.lua
@@ -520,4 +520,42 @@ describe('statuscolumn', function()
: |
]])
end)
+
+ it("has correct width when toggling '(relative)number'", function()
+ screen:try_resize(screen._width, 6)
+ command('call setline(1, repeat(["aaaaa"], 100))')
+ command('set relativenumber')
+ command([[set stc=%{!&nu&&!&rnu?'':&rnu?v:relnum?v:relnum:&nu?v:lnum:'0':v:lnum}]])
+ screen:expect([[
+ 1 aaaaa |
+ 8 ^aaaaa |
+ 1 aaaaa |
+ 2 aaaaa |
+ 3 aaaaa |
+ |
+ ]])
+ -- width correctly estimated with "w_nrwidth_line_count" when setting 'stc'
+ command([[set stc=%{!&nu&&!&rnu?'':&rnu?v:relnum?v:relnum:&nu?v:lnum:'0':v:lnum}]])
+ screen:expect_unchanged()
+ -- zero width when disabling 'number'
+ command('set norelativenumber nonumber')
+ screen:expect([[
+ aaaaa |
+ ^aaaaa |
+ aaaaa |
+ aaaaa |
+ aaaaa |
+ |
+ ]])
+ -- width correctly estimated with "w_nrwidth_line_count" when setting 'nu'
+ command('set number')
+ screen:expect([[
+ 7 aaaaa |
+ 8 ^aaaaa |
+ 9 aaaaa |
+ 10 aaaaa |
+ 11 aaaaa |
+ |
+ ]])
+ end)
end)