Skip to content

Commit

Permalink
fix(statuscolumn): make %l/%r respect 'number'/'relativenumber' (neov…
Browse files Browse the repository at this point in the history
  • Loading branch information
luukvbaal authored and yesean committed Mar 25, 2023
1 parent 6fac560 commit ba6be4c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/nvim/statusline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions test/functional/ui/statuscolumn_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ describe('statuscolumn', function()
16│aaaaa |
|
]])
command([[set stc=%l%=%{&rnu?'\ ':''}%r│]])
screen:expect_unchanged()
command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]])
command('set relativenumber')
screen:expect([[
4 4│aaaaa |
Expand All @@ -94,6 +97,9 @@ describe('statuscolumn', function()
16 8│aaaaa |
|
]])
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 |
Expand All @@ -111,6 +117,9 @@ describe('statuscolumn', function()
16 12│aaaaa |
|
]])
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()
Expand Down

0 comments on commit ba6be4c

Please sign in to comment.