feat(column)!: rework 'statuscolumn' %r/l items

Problem:  A custom 'statuscolumn' needs to check a bunch of options and
          placed signs to replicate the default number column.
Solution: Rework %l item to include the necessary logic to mimic the
          default number column. Remove now redundant %r item.
This commit is contained in:
Luuk van Baal
2024-06-15 05:46:43 +02:00
parent 114197517f
commit ad70c9892d
10 changed files with 251 additions and 202 deletions

View File

@ -62,7 +62,10 @@ LUA
OPTIONS OPTIONS
• TODO • The 'statuscolumn' `%l` item can now be used as a number column segment that
changes according to related options. It takes care of alignment, 'number',
'relativenumber' and 'signcolumn' set to "number". The now redundant `%r` item
is no longer treated specially for 'statuscolumn'.
PLUGINS PLUGINS

View File

@ -5951,8 +5951,7 @@ A jump table for the options with a short description can be found at |Q_op|.
Some of the items from the 'statusline' format are different for Some of the items from the 'statusline' format are different for
'statuscolumn': 'statuscolumn':
%l line number of currently drawn line %l line number column for currently drawn line
%r relative line number of currently drawn line
%s sign column for currently drawn line %s sign column for currently drawn line
%C fold column for currently drawn line %C fold column for currently drawn line
@ -5979,11 +5978,8 @@ A jump table for the options with a short description can be found at |Q_op|.
handler should be written with this in mind. handler should be written with this in mind.
Examples: >vim Examples: >vim
" Relative number with bar separator and click handlers: " Line number with bar separator and click handlers:
set statuscolumn=%@SignCb@%s%=%T%@NumCb@%r│%T set statuscolumn=%@SignCb@%s%=%T%@NumCb@%l│%T
" Right aligned relative cursor line number:
let &stc='%=%{v:relnum?v:relnum:v:lnum} '
" Line numbers in hexadecimal for non wrapped part of lines: " Line numbers in hexadecimal for non wrapped part of lines:
let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} ' let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} '

View File

@ -6373,8 +6373,7 @@ vim.go.sol = vim.go.startofline
--- Some of the items from the 'statusline' format are different for --- Some of the items from the 'statusline' format are different for
--- 'statuscolumn': --- 'statuscolumn':
--- ---
--- %l line number of currently drawn line --- %l line number column for currently drawn line
--- %r relative line number of currently drawn line
--- %s sign column for currently drawn line --- %s sign column for currently drawn line
--- %C fold column for currently drawn line --- %C fold column for currently drawn line
--- ---
@ -6403,11 +6402,8 @@ vim.go.sol = vim.go.startofline
--- Examples: --- Examples:
--- ---
--- ```vim --- ```vim
--- " Relative number with bar separator and click handlers: --- " Line number with bar separator and click handlers:
--- set statuscolumn=%@SignCb@%s%=%T%@NumCb@%r│%T --- set statuscolumn=%@SignCb@%s%=%T%@NumCb@%l│%T
---
--- " Right aligned relative cursor line number:
--- let &stc='%=%{v:relnum?v:relnum:v:lnum} '
--- ---
--- " Line numbers in hexadecimal for non wrapped part of lines: --- " Line numbers in hexadecimal for non wrapped part of lines:
--- let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} ' --- let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} '

View File

@ -587,12 +587,13 @@ static void draw_statuscol(win_T *wp, winlinevars_T *wlv, linenr_T lnum, int vir
char buf[MAXPATHL]; char buf[MAXPATHL];
// When a buffer's line count has changed, make a best estimate for the full // When a buffer's line count has changed, make a best estimate for the full
// width of the status column by building with "w_nrwidth_line_count". Add // width of the status column by building with the largest possible line number.
// potentially truncated width and rebuild before drawing anything. // Add potentially truncated width and rebuild before drawing anything.
if (wp->w_statuscol_line_count != wp->w_nrwidth_line_count) { if (wp->w_statuscol_line_count != wp->w_nrwidth_line_count) {
wp->w_statuscol_line_count = wp->w_nrwidth_line_count; wp->w_statuscol_line_count = wp->w_nrwidth_line_count;
set_vim_var_nr(VV_VIRTNUM, 0); set_vim_var_nr(VV_VIRTNUM, 0);
int width = build_statuscol_str(wp, wp->w_nrwidth_line_count, 0, buf, stcp); int width = build_statuscol_str(wp, wp->w_nrwidth_line_count,
wp->w_nrwidth_line_count, buf, stcp);
if (width > stcp->width) { if (width > stcp->width) {
int addwidth = MIN(width - stcp->width, MAX_STCWIDTH - stcp->width); int addwidth = MIN(width - stcp->width, MAX_STCWIDTH - stcp->width);
wp->w_nrwidth += addwidth; wp->w_nrwidth += addwidth;

View File

@ -8037,8 +8037,7 @@ return {
Some of the items from the 'statusline' format are different for Some of the items from the 'statusline' format are different for
'statuscolumn': 'statuscolumn':
%l line number of currently drawn line %l line number column for currently drawn line
%r relative line number of currently drawn line
%s sign column for currently drawn line %s sign column for currently drawn line
%C fold column for currently drawn line %C fold column for currently drawn line
@ -8065,11 +8064,8 @@ return {
handler should be written with this in mind. handler should be written with this in mind.
Examples: >vim Examples: >vim
" Relative number with bar separator and click handlers: " Line number with bar separator and click handlers:
set statuscolumn=%@SignCb@%s%=%T%@NumCb@%r│%T set statuscolumn=%@SignCb@%s%=%T%@NumCb@%l│%T
" Right aligned relative cursor line number:
let &stc='%=%{v:relnum?v:relnum:v:lnum} '
" Line numbers in hexadecimal for non wrapped part of lines: " Line numbers in hexadecimal for non wrapped part of lines:
let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} ' let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} '

View File

@ -1017,7 +1017,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
int evaldepth = 0; int evaldepth = 0;
int curitem = 0; int curitem = 0;
int foldsignitem = -1;
bool prevchar_isflag = true; bool prevchar_isflag = true;
bool prevchar_isitem = false; bool prevchar_isitem = false;
@ -1234,6 +1233,8 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
} }
int minwid = 0; int minwid = 0;
int maxwid = 9999; int maxwid = 9999;
int foldsignitem = -1; // Start of fold or sign item
bool left_align_num = false; // Number item for should be left-aligned
bool left_align = false; bool left_align = false;
// Denotes that numbers should be left-padded with zeros // Denotes that numbers should be left-padded with zeros
@ -1505,12 +1506,20 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
} }
case STL_LINE: case STL_LINE:
// Overload %l with v:lnum for 'statuscolumn' // Overload %l with v:(re)lnum for 'statuscolumn'. Place a sign when 'signcolumn'
if (stcp != NULL) { // is set to "number". Take care of alignment for 'number' + 'relativenumber'.
if (wp->w_p_nu && !get_vim_var_nr(VV_VIRTNUM)) { if (stcp != NULL && (wp->w_p_nu || wp->w_p_rnu) && get_vim_var_nr(VV_VIRTNUM) == 0) {
num = (int)get_vim_var_nr(VV_LNUM); if (wp->w_maxscwidth == SCL_NUM && stcp->sattrs[0].text[0]) {
goto stcsign;
} }
} else { int relnum = (int)get_vim_var_nr(VV_RELNUM);
num = (!wp->w_p_rnu || (wp->w_p_nu && relnum == 0)) ? (int)get_vim_var_nr(VV_LNUM) : relnum;
left_align_num = wp->w_p_rnu && wp->w_p_nu && relnum == 0;
if (!left_align_num) {
stl_items[curitem].type = Separate;
stl_items[curitem++].start = out_p;
}
} else if (stcp == NULL) {
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) ? 0 : wp->w_cursor.lnum; num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) ? 0 : wp->w_cursor.lnum;
} }
break; break;
@ -1609,16 +1618,9 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
case STL_ROFLAG: case STL_ROFLAG:
case STL_ROFLAG_ALT: case STL_ROFLAG_ALT:
// Overload %r with v:relnum for 'statuscolumn' itemisflag = true;
if (stcp != NULL) { if (wp->w_buffer->b_p_ro) {
if (wp->w_p_rnu && !get_vim_var_nr(VV_VIRTNUM)) { str = (opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]");
num = (int)get_vim_var_nr(VV_RELNUM);
}
} else {
itemisflag = true;
if (wp->w_buffer->b_p_ro) {
str = (opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]");
}
} }
break; break;
@ -1632,11 +1634,12 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
case STL_FOLDCOL: // 'C' for 'statuscolumn' case STL_FOLDCOL: // 'C' for 'statuscolumn'
case STL_SIGNCOL: { // 's' for 'statuscolumn' case STL_SIGNCOL: { // 's' for 'statuscolumn'
stcsign:
if (stcp == NULL) { if (stcp == NULL) {
break; break;
} }
int fdc = opt == STL_FOLDCOL ? compute_foldcolumn(wp, 0) : 0; int fdc = opt == STL_FOLDCOL ? compute_foldcolumn(wp, 0) : 0;
int width = opt == STL_FOLDCOL ? fdc > 0 : wp->w_scwidth; int width = opt == STL_FOLDCOL ? fdc > 0 : opt == STL_SIGNCOL ? wp->w_scwidth : 1;
if (width <= 0) { if (width <= 0) {
break; break;
@ -1844,7 +1847,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
// For a 'statuscolumn' sign or fold item, add an item to reset the highlight group // For a 'statuscolumn' sign or fold item, add an item to reset the highlight group
if (foldsignitem >= 0) { if (foldsignitem >= 0) {
foldsignitem = -1;
stl_items[curitem].type = Highlight; stl_items[curitem].type = Highlight;
stl_items[curitem].start = out_p; stl_items[curitem].start = out_p;
stl_items[curitem].minwid = 0; stl_items[curitem].minwid = 0;
@ -1949,6 +1951,11 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
// Item processed, move to the next // Item processed, move to the next
curitem++; curitem++;
// For a 'statuscolumn' number item that is left aligned, add a separator item.
if (left_align_num) {
stl_items[curitem].type = Separate;
stl_items[curitem++].start = out_p;
}
} }
*out_p = NUL; *out_p = NUL;

View File

@ -3887,11 +3887,11 @@ describe('API', function()
)) ))
eq( eq(
{ {
str = '3 ', str = ' 3 ',
width = 2, width = 9,
highlights = { highlights = {
{ group = 'LineNr', start = 0 }, { group = 'LineNr', start = 0 },
{ group = 'ErrorMsg', start = 1 }, { group = 'ErrorMsg', start = 8 },
}, },
}, },
api.nvim_eval_statusline('%l%#ErrorMsg# ', { use_statuscol_lnum = 3, highlights = true }) api.nvim_eval_statusline('%l%#ErrorMsg# ', { use_statuscol_lnum = 3, highlights = true })

View File

@ -130,9 +130,9 @@ describe(':terminal window', function()
]]) ]])
feed_data('\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') feed_data('\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
screen:expect([[ screen:expect([[
{7:++7 } | {7:++ 7 } |
{7:++8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR| {7:++ 8 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
{7:++9 }TUVWXYZ | {7:++ 9 }TUVWXYZ |
{7:++10 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR| {7:++10 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR|
{7:++11 }TUVWXYZrows: 6, cols: 44 | {7:++11 }TUVWXYZrows: 6, cols: 44 |
{7:++12 }{1: } | {7:++12 }{1: } |

View File

@ -1532,9 +1532,9 @@ describe('float window', function()
[2:----------------------------------------]|*6 [2:----------------------------------------]|*6
[3:----------------------------------------]| [3:----------------------------------------]|
## grid 2 ## grid 2
{20:1}{19: }{20: }{22:^x}{21: }| {20: 1}{19: }{22:^x}{21: }|
{14:2}{19: }{14: }{22:y} | {14: 2}{19: }{22:y} |
{14:3}{19: }{14: }{22: } | {14: 3}{19: }{22: } |
{0:~ }|*3 {0:~ }|*3
## grid 3 ## grid 3
| |
@ -1545,9 +1545,9 @@ describe('float window', function()
]], float_pos={[4] = {1001, "NW", 1, 4, 10, true}}} ]], float_pos={[4] = {1001, "NW", 1, 4, 10, true}}}
else else
screen:expect{grid=[[ screen:expect{grid=[[
{20:1}{19: }{20: }{22:^x}{21: }| {20: 1}{19: }{22:^x}{21: }|
{14:2}{19: }{14: }{22:y} | {14: 2}{19: }{22:y} |
{14:3}{19: }{14: }{22: } {15:x } | {14: 3}{19: }{22: } {15:x } |
{0:~ }{15:y }{0: }| {0:~ }{15:y }{0: }|
{0:~ }{15: }{0: }|*2 {0:~ }{15: }{0: }|*2
| |

View File

@ -94,46 +94,80 @@ describe('statuscolumn', function()
end) end)
it("works with 'number' and 'relativenumber'", function() it("works with 'number' and 'relativenumber'", function()
command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]])
screen:expect([[ screen:expect([[
{8:4 }aaaaa | {8: 4 }aaaaa |
{8:5 }aaaaa | {8: 5 }aaaaa |
{8:6 }aaaaa | {8: 6 }aaaaa |
{8:7 }aaaaa | {8: 7 }aaaaa |
{8:8 }^aaaaa | {8: 8 }^aaaaa |
{8:9 }aaaaa | {8: 9 }aaaaa |
{8:10}aaaaa | {8:10 }aaaaa |
{8:11}aaaaa | {8:11 }aaaaa |
{8:12}aaaaa | {8:12 }aaaaa |
{8:13}aaaaa | {8:13 }aaaaa |
{8:14}aaaaa | {8:14 }aaaaa |
{8:15}aaaaa | {8:15 }aaaaa |
{8:16}aaaaa | {8:16 }aaaaa |
| |
]]) ]])
command([[set stc=%l%=%{&rnu?'\ ':''}%r│]]) command([[set stc=%l\ ]])
screen:expect_unchanged() screen:expect_unchanged()
command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]])
command('set relativenumber') command('set relativenumber')
screen:expect([[ screen:expect([[
{8:4 4}aaaaa | {8: 4 }aaaaa |
{8:5 3}aaaaa | {8: 3 }aaaaa |
{8:6 2}aaaaa | {8: 2 }aaaaa |
{8:7 1}aaaaa | {8: 1 }aaaaa |
{8:8 0│}^aaaaa | {8:8 }^aaaaa |
{8:9 1}aaaaa | {8: 1 }aaaaa |
{8:10 2}aaaaa | {8: 2 }aaaaa |
{8:11 3}aaaaa | {8: 3 }aaaaa |
{8:12 4}aaaaa | {8: 4 }aaaaa |
{8:13 5}aaaaa | {8: 5 }aaaaa |
{8:14 6}aaaaa | {8: 6 }aaaaa |
{8:15 7}aaaaa | {8: 7 }aaaaa |
{8:16 8}aaaaa | {8: 8 }aaaaa |
| |
]]) ]])
command([[set stc=%l%=%{&rnu?'\ ':''}%r│]]) command('set stc=')
screen:expect_unchanged() screen:expect_unchanged()
command([[set stc=%{&nu?v:lnum:''}%=%{&rnu?'\ '.v:relnum:''}│]]) command([[set nonu stc=%l\ ]])
screen:expect([[
{8: 4 }aaaaa |
{8: 3 }aaaaa |
{8: 2 }aaaaa |
{8: 1 }aaaaa |
{8: 0 }^aaaaa |
{8: 1 }aaaaa |
{8: 2 }aaaaa |
{8: 3 }aaaaa |
{8: 4 }aaaaa |
{8: 5 }aaaaa |
{8: 6 }aaaaa |
{8: 7 }aaaaa |
{8: 8 }aaaaa |
|
]])
command('set nuw=1 stc=')
screen:expect_unchanged()
-- Correct alignment with items before and after number column
command([[set nu stc=foo\ %l\ bar]])
screen:expect([[
{8:foo 4 bar}aaaaa |
{8:foo 3 bar}aaaaa |
{8:foo 2 bar}aaaaa |
{8:foo 1 bar}aaaaa |
{8:foo 8 bar}^aaaaa |
{8:foo 1 bar}aaaaa |
{8:foo 2 bar}aaaaa |
{8:foo 3 bar}aaaaa |
{8:foo 4 bar}aaaaa |
{8:foo 5 bar}aaaaa |
{8:foo 6 bar}aaaaa |
{8:foo 7 bar}aaaaa |
{8:foo 8 bar}aaaaa |
|
]])
end) end)
it("works with highlighted 'statuscolumn'", function() it("works with highlighted 'statuscolumn'", function()
@ -160,36 +194,36 @@ describe('statuscolumn', function()
]]) ]])
command('set relativenumber') command('set relativenumber')
screen:expect([[ screen:expect([[
{1:4 }{8: 4│}aaaaa | {1:4 }{8: 4│}aaaaa |
{1:5 3}{8:│}aaaaa | {1:5 3}{8:│}aaaaa |
{1:6 }{8: 2│}aaaaa | {1:6 }{8: 2│}aaaaa |
{1:7 1}{8:│}aaaaa | {1:7 1}{8:│}aaaaa |
{1:8 }{8: 0│}^aaaaa | {1:8 }{8: 0│}^aaaaa |
{1:9 1}{8:│}aaaaa | {1:9 1}{8:│}aaaaa |
{1:10}{8: 2│}aaaaa | {1:10 }{8: 2│}aaaaa |
{1:11 3}{8:│}aaaaa | {1:11 3}{8:│}aaaaa |
{1:12}{8: 4│}aaaaa | {1:12 }{8: 4│}aaaaa |
{1:13 5}{8:│}aaaaa | {1:13 5}{8:│}aaaaa |
{1:14}{8: 6│}aaaaa | {1:14 }{8: 6│}aaaaa |
{1:15 7}{8:│}aaaaa | {1:15 7}{8:│}aaaaa |
{1:16}{8: 8│}aaaaa | {1:16 }{8: 8│}aaaaa |
| |
]]) ]])
command('set nonumber') command('set nonumber')
screen:expect([[ screen:expect([[
{8:4│}aaaaa | {1: }{8:4│}aaaaa |
{1:3}{8:│}aaaaa | {1: 3}{8:│}aaaaa |
{8:2│}aaaaa | {1: }{8:2│}aaaaa |
{1:1}{8:│}aaaaa | {1: 1}{8:│}aaaaa |
{8:0│}^aaaaa | {1: }{8:0│}^aaaaa |
{1:1}{8:│}aaaaa | {1: 1}{8:│}aaaaa |
{8:2│}aaaaa | {1: }{8:2│}aaaaa |
{1:3}{8:│}aaaaa | {1: 3}{8:│}aaaaa |
{8:4│}aaaaa | {1: }{8:4│}aaaaa |
{1:5}{8:│}aaaaa | {1: 5}{8:│}aaaaa |
{8:6│}aaaaa | {1: }{8:6│}aaaaa |
{1:7}{8:│}aaaaa | {1: 7}{8:│}aaaaa |
{8:8│}aaaaa | {1: }{8:8│}aaaaa |
| |
]]) ]])
end) end)
@ -305,36 +339,36 @@ describe('statuscolumn', function()
-- v:relnum is the same value on wrapped lines -- v:relnum is the same value on wrapped lines
command([[set stc=%C%=\ %{v:relnum}│%s\ ]]) command([[set stc=%C%=\ %{v:relnum}│%s\ ]])
screen:expect([[ screen:expect([[
{2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 4│}{2: }{1: }aaaaaa | {2: }{1: 4│}{2: }{1: }aaaaaaa |
{2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 3│}{2: }{1: }aaaaaa | {2: }{1: 3│}{2: }{1: }aaaaaaa |
{2: }{1: 2│}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 2│}{2: }{1: }aaaaaa | {2: }{1: 2│}{2: }{1: }aaaaaaa |
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 1│}{2: }{1: }aaaaaa | {2: }{1: 1│}{2: }{1: }aaaaaaa |
{2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| {2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 1│}{2: }{1: }aaaaaa | {2: }{1: 1│}{2: }{1: }aaaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: 2│}{2: }{1: }aaaaaa | {2: }{1: 2│}{2: }{1: }aaaaaaa |
| |
]]) ]])
command([[set stc=%C%=\ %{v:virtnum?'':v:relnum}│%s\ ]]) command([[set stc=%C%=\ %{v:virtnum?'':v:relnum}│%s\ ]])
screen:expect([[ screen:expect([[
{2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: │}{2: }{1: }aaaaaaa |
{2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: │}{2: }{1: }aaaaaaa |
{2: }{1: 2│}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: │}{2: }{1: }aaaaaaa |
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: │}{2: }{1: }aaaaaaa |
{2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| {2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: │}{2: }{1: }aaaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaa | {2: }{1: │}{2: }{1: }aaaaaaa |
| |
]]) ]])
-- Up to 9 signs in a line -- Up to 9 signs in a line
@ -347,75 +381,75 @@ describe('statuscolumn', function()
command('sign place 10 line=6 name=piet2 buffer=1') command('sign place 10 line=6 name=piet2 buffer=1')
command('sign place 11 line=6 name=piet1 buffer=1') command('sign place 11 line=6 name=piet1 buffer=1')
screen:expect([[ screen:expect([[
{2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 4│>>}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaaa |
{2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaaa}| {2:+}{4: 0│}{2: }{4: }{6:^+-- 1 line: aaaaaaaaaaaaaaaa}|
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaa | {2: }{1: │}{2: }{1: }aaaaaaaaaaaaaaaaaaaaa |
| |
]]) ]])
-- Also test fold and sign column when 'cpoptions' includes "n" -- Also test fold and sign column when 'cpoptions' includes "n"
command('set cpoptions+=n') command('set cpoptions+=n')
feed('Hgjg0') feed('Hgjg0')
screen:expect([[ screen:expect([[
{2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| {2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{5:^aaaaaaaaaaaaaaaaaaaa }| {2: }{5:^aaaaaaaaaaaaaaaaaaaaa }|
{2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 3│}{0:>!}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
{2:+}{1: 4│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}| {2:+}{1: 4│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaa}|
{2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
| |
]]) ]])
command('set breakindent') command('set breakindent')
command('sign unplace 2') command('sign unplace 2')
feed('J2gjg0') feed('J2gjg0')
screen:expect([[ screen:expect([[
{2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| {2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: } {5:aaaaaaaaaaaaaaaaaaaa aaaaaaaaa}| {2: } {5:aaaaaaaaaaaaaaaaaaaaa aaaaaaa}|
{2: } {5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| {2: } {5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: } {5:^aaaaaaaaaaa }| {2: } {5:^aaaaaaaaaaaaaa }|
{2: }{1: 1│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa | {2: } aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa | {2: } aaaaaaaaaaaaaaaaaaaaa |
{2:+}{1: 3│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}| {2:+}{1: 3│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaa}|
{2: }{1: 4│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 4│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa | {2: } aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 5│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 5│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: } aaaaaaaaaaaaaaaaaaaa | {2: } aaaaaaaaaaaaaaaaaaaaa |
| |
]]) ]])
command('set nobreakindent') command('set nobreakindent')
feed('$g0') feed('$g0')
screen:expect([[ screen:expect([[
{2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| {2: }{4: 0│}{1:>>}{2: }{4: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{5:aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaa}| {2: }{5:aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaa}|
{2: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}| {2: }{5:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{2: }{5:^aaa }| {2: }{5:^aaaa }|
{2: }{1: 1│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 1│>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>>}{0:>!}{1:>> }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 2│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
{2:+}{1: 3│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaaa}| {2:+}{1: 3│}{2: }{1: }{3:+-- 1 line: aaaaaaaaaaaaaaaa}|
{2: }{1: 4│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 4│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
{2: }{1: 5│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| {2: }{1: 5│}{2: }{1: }aaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{2: }aaaaaaaaaaaaaaaaaaaa | {2: }aaaaaaaaaaaaaaaaaaaaa |
| |
]]) ]])
command('silent undo') command('silent undo')
@ -427,7 +461,23 @@ describe('statuscolumn', function()
virt_lines_above = true, virt_lines = {{{"virt_line above", ""}}} }) virt_lines_above = true, virt_lines = {{{"virt_line above", ""}}} })
vim.api.nvim_buf_set_extmark(0, ns, 4, 0, { virt_lines = {{{"virt_line", ""}}} }) vim.api.nvim_buf_set_extmark(0, ns, 4, 0, { virt_lines = {{{"virt_line", ""}}} })
]]) ]])
command('set foldcolumn=0 signcolumn=no') command('set foldcolumn=0 signcolumn=number stc=%l')
screen:expect([[
{1:>>}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1: 5}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1: }virt_line |
{1: }virt_line above |
{1:>>}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1: 7}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{4: 8}{6:^+-- 1 line: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{1: 9}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1:10}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1:11}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1:12}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1:13}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
{1:14}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
]])
command( command(
[[set stc=%{v:virtnum<0?'virtual':(!v:virtnum?'buffer':'wrapped')}%=%{'\ '.v:virtnum.'\ '.v:lnum}]] [[set stc=%{v:virtnum<0?'virtual':(!v:virtnum?'buffer':'wrapped')}%=%{'\ '.v:virtnum.'\ '.v:lnum}]]
) )
@ -533,8 +583,8 @@ describe('statuscolumn', function()
command([[set stc=%6s\ %l]]) command([[set stc=%6s\ %l]])
exec_lua('vim.api.nvim_buf_set_extmark(0, ns, 7, 0, {sign_text = "𒀀"})') exec_lua('vim.api.nvim_buf_set_extmark(0, ns, 7, 0, {sign_text = "𒀀"})')
screen:expect([[ screen:expect([[
{8: 𒀀 8 }^aaaaa | {8: 𒀀 8}^aaaaa |
{8: }{7: }{8: 9 }aaaaa | {8: }{7: }{8: 9}aaaaa |
| |
]]) ]])
end) end)
@ -644,26 +694,26 @@ describe('statuscolumn', function()
-- clicking an item does not drag mouse -- clicking an item does not drag mouse
api.nvim_input_mouse('left', 'press', '', 0, 0, 0) api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
screen:expect([[ screen:expect([[
{0:8 }^aaaaa | {0: 8}^aaaaa |
{1: Echo } | {1: Echo } |
]]) ]])
api.nvim_input_mouse('left', 'press', '', 0, 1, 5) api.nvim_input_mouse('left', 'press', '', 0, 1, 5)
api.nvim_input_mouse('left', 'release', '', 0, 1, 5) api.nvim_input_mouse('left', 'release', '', 0, 1, 5)
screen:expect([[ screen:expect([[
{0:8 }^aaaaa | {0: 8}^aaaaa |
0 1 l 8 | 0 1 l 8 |
]]) ]])
command('echo') command('echo')
-- clicking outside to close the menu does not drag mouse -- clicking outside to close the menu does not drag mouse
api.nvim_input_mouse('left', 'press', '', 0, 0, 0) api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
screen:expect([[ screen:expect([[
{0:8 }^aaaaa | {0: 8}^aaaaa |
{1: Echo } | {1: Echo } |
]]) ]])
api.nvim_input_mouse('left', 'press', '', 0, 0, 10) api.nvim_input_mouse('left', 'press', '', 0, 0, 10)
api.nvim_input_mouse('left', 'release', '', 0, 0, 10) api.nvim_input_mouse('left', 'release', '', 0, 0, 10)
screen:expect([[ screen:expect([[
{0:8 }^aaaaa | {0: 8}^aaaaa |
| |
]]) ]])
end) end)
@ -749,9 +799,9 @@ describe('statuscolumn', function()
it('works with cmdwin', function() it('works with cmdwin', function()
feed(':set stc=%l<CR>q:k$') feed(':set stc=%l<CR>q:k$')
screen:expect([[ screen:expect([[
{8:7 }aaaaa | {8: 7}aaaaa |
{8:8 }aaaaa | {8: 8}aaaaa |
{8:9 }aaaaa | {8: 9}aaaaa |
{8:10}aaaaa | {8:10}aaaaa |
{2:[No Name] [+] }| {2:[No Name] [+] }|
{1::}{8:1}set stc=%^l | {1::}{8:1}set stc=%^l |
@ -899,16 +949,16 @@ describe('statuscolumn', function()
command([[set spell stc=%l\ ]]) command([[set spell stc=%l\ ]])
command('call setline(8, "This is a line that contains ᶏ multibyte character.")') command('call setline(8, "This is a line that contains ᶏ multibyte character.")')
screen:expect([[ screen:expect([[
{8:8 }^This is a line that contains {31:ᶏ}| {8: 8 }^This is a line that contains {31:ᶏ}|
{8: } {31:multibyte} character. | {8: } {31:multibyte} character. |
{8:9 }{31:aaaaa} | {8: 9 }{31:aaaaa} |
| |
]]) ]])
end) end)
it('line increase properly redraws buffer text with relativenumber #27709', function() it('line increase properly redraws buffer text with relativenumber #27709', function()
screen:try_resize(33, 4) screen:try_resize(33, 4)
command([[set rnu nuw=3 stc=%l\ ]]) command([[set rnu nuw=3 stc=%{v:lnum}\ ]])
command('call setline(1, range(1, 99))') command('call setline(1, range(1, 99))')
feed('Gyyp') feed('Gyyp')
screen:expect([[ screen:expect([[