Skip to content

Commit

Permalink
statuscolumn: make %l follow default wrap behavior
Browse files Browse the repository at this point in the history
Omit line numbers on lines that are wrapped or virtual, matching the
behavior prior to statuscolumn. This can always be overridden using
`%{}` expressions.
  • Loading branch information
bkoropoff committed Jan 12, 2023
1 parent 2a8942a commit 35cd743
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/nvim/drawline.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static void get_statuscol_str(win_T *wp, linenr_T lnum, int row, int startrow, i
}
stcp->sign_text[i] = NULL;

int width = build_statuscol_str(wp, row == startrow, wrapped, lnum, relnum,
int width = build_statuscol_str(wp, wrapped, lnum, relnum,
stcp->width, ' ', stcp->text, &stcp->hlrec, stcp);
// Force a redraw in case of error or when truncated
if (*wp->w_p_stc == NUL || (stcp->truncate > 0 && wp->w_nrwidth < MAX_NUMBERWIDTH)) {
Expand Down
2 changes: 1 addition & 1 deletion src/nvim/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ int number_width(win_T *wp)
if (*wp->w_p_stc != NUL) {
char buf[MAXPATHL];
wp->w_nrwidth_width = 0;
n = build_statuscol_str(wp, true, false, lnum, 0, 0, NUL, buf, NULL, NULL);
n = build_statuscol_str(wp, false, lnum, 0, 0, NUL, buf, NULL, NULL);
n = MAX(n, (wp->w_p_nu || wp->w_p_rnu) * (int)wp->w_p_nuw);
wp->w_nrwidth_width = MIN(n, MAX_NUMBERWIDTH);
return wp->w_nrwidth_width;
Expand Down
8 changes: 4 additions & 4 deletions src/nvim/statusline.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,10 @@ void draw_tabline(void)
/// @param hlrec HL attributes (can be NULL)
/// @param stcp Status column attributes (can be NULL)
/// @return The width of the built status column string for line "lnum"
int build_statuscol_str(win_T *wp, bool setnum, bool wrap, linenr_T lnum, long relnum, int maxwidth,
int build_statuscol_str(win_T *wp, bool wrap, linenr_T lnum, long relnum, int maxwidth,
int fillchar, char *buf, stl_hlrec_t **hlrec, statuscol_T *stcp)
{
if (setnum) {
if (!wrap) {
set_vim_var_nr(VV_LNUM, lnum);
set_vim_var_nr(VV_RELNUM, relnum);
}
Expand Down Expand Up @@ -1503,7 +1503,7 @@ 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'
if (opt_name != NULL && strcmp(opt_name, "statuscolumn") == 0) {
if (wp->w_p_nu) {
if (wp->w_p_nu && !get_vim_var_nr(VV_WRAP)) {
num = get_vim_var_nr(VV_LNUM);
}
} else {
Expand Down Expand Up @@ -1609,7 +1609,7 @@ 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) {
if (wp->w_p_rnu) {
if (wp->w_p_rnu && !get_vim_var_nr(VV_WRAP)) {
num = get_vim_var_nr(VV_RELNUM);
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/functional/ui/statuscolumn_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ describe('statuscolumn', function()
{1:10│ }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{0:@@@}|
|
]])
command("set stc=%C%s%=%l│\\ ")
screen:expect_unchanged()
command('set signcolumn=auto:2 foldcolumn=auto')
command('sign define piet1 text=>> texthl=LineNr')
command('sign define piet2 text=>! texthl=NonText')
Expand Down

0 comments on commit 35cd743

Please sign in to comment.