fix(statuscolumn): make %l/%r respect 'number'/'relativenumber' (#21747)

Resolve https://github.com/neovim/neovim/issues/21745.
This commit is contained in:
luukvbaal 2023-01-13 10:41:19 +01:00 committed by GitHub
parent 449c0762d3
commit 4a12372ccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -1502,8 +1502,14 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
case STL_LINE:
// Overload %l with v:lnum for 'statuscolumn'
num = opt_name != NULL && strcmp(opt_name, "statuscolumn") == 0 ? get_vim_var_nr(VV_LNUM)
: (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) ? 0L : (long)(wp->w_cursor.lnum);
if (opt_name != NULL && strcmp(opt_name, "statuscolumn") == 0) {
if (wp->w_p_nu) {
num = get_vim_var_nr(VV_LNUM);
}
} else {
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) ? 0L : (long)(wp->w_cursor.lnum);
}
break;
case STL_NUMLINES:
@ -1603,7 +1609,9 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
case STL_ROFLAG_ALT:
// Overload %r with v:relnum for 'statuscolumn'
if (opt_name != NULL && strcmp(opt_name, "statuscolumn") == 0) {
num = get_vim_var_nr(VV_RELNUM);
if (wp->w_p_rnu) {
num = get_vim_var_nr(VV_RELNUM);
}
} else {
itemisflag = true;
if (wp->w_buffer->b_p_ro) {

View File

@ -77,6 +77,9 @@ describe('statuscolumn', function()
16aaaaa |
|
]])
command([[set stc=%l%=%{&rnu?'\ ':''}%r│]])
screen:expect_unchanged()
command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]])
command('set relativenumber')
screen:expect([[
4 4aaaaa |
@ -94,6 +97,9 @@ describe('statuscolumn', function()
16 8aaaaa |
|
]])
command([[set stc=%l%=%{&rnu?'\ ':''}%r│]])
screen:expect_unchanged()
command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]])
command('norm 12GH')
screen:expect([[
4 0^aaaaa |
@ -111,6 +117,9 @@ describe('statuscolumn', function()
16 12aaaaa |
|
]])
command([[set stc=%l%=%{&rnu?'\ ':''}%r│]])
screen:expect_unchanged()
command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]])
end)
it('works with highlighted \'statuscolumn\'', function()