aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ui/statuscolumn_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/ui/statuscolumn_spec.lua')
-rw-r--r--test/functional/ui/statuscolumn_spec.lua289
1 files changed, 180 insertions, 109 deletions
diff --git a/test/functional/ui/statuscolumn_spec.lua b/test/functional/ui/statuscolumn_spec.lua
index 6eaf15cfad..41406a5860 100644
--- a/test/functional/ui/statuscolumn_spec.lua
+++ b/test/functional/ui/statuscolumn_spec.lua
@@ -7,11 +7,11 @@ local exec = helpers.exec
local eval = helpers.eval
local exec_lua = helpers.exec_lua
local feed = helpers.feed
-local meths = helpers.meths
+local api = helpers.api
local pcall_err = helpers.pcall_err
local assert_alive = helpers.assert_alive
-local mousemodels = { "extend", "popup", "popup_setpos" }
+local mousemodels = { 'extend', 'popup', 'popup_setpos' }
describe('statuscolumn', function()
local screen
@@ -23,7 +23,9 @@ describe('statuscolumn', function()
end)
it("fails with invalid 'statuscolumn'", function()
- command([[set stc=%{v:relnum?v:relnum:(v:lnum==5?invalid:v:lnum)}\ ]])
+ command(
+ [[set stc=%{v:relnum?v:relnum:(v:lnum==5?'truncate':v:lnum)}%{!v:relnum&&v:lnum==5?invalid:''}\ ]]
+ )
screen:expect([[
4 aaaaa |
3 aaaaa |
@@ -43,6 +45,22 @@ describe('statuscolumn', function()
command('norm 5G')
eq('Vim(redraw):E121: Undefined variable: invalid', pcall_err(command, 'redraw!'))
eq('', eval('&statuscolumn'))
+ screen:expect([[
+ 4 aaaaa |
+ 5 ^aaaaa |
+ 6 aaaaa |
+ 7 aaaaa |
+ 8 aaaaa |
+ 9 aaaaa |
+ 10 aaaaa |
+ 11 aaaaa |
+ 12 aaaaa |
+ 13 aaaaa |
+ 14 aaaaa |
+ 15 aaaaa |
+ 16 aaaaa |
+ |
+ ]])
end)
it("widens with irregular 'statuscolumn' width", function()
@@ -59,6 +77,18 @@ describe('statuscolumn', function()
1 aaaaa |
|
]])
+ -- Doesn't crash when trying to fill click defs that do not fit (#26845)
+ command('norm gg')
+ command([=[
+ set stc=%@Click@%{v:relnum?v:relnum:(v:lnum==5?'bbbbb':v:lnum)}%T
+ norm 5Gzt | redraw!
+ ]=])
+ screen:expect([[
+ bbbbba^eaaa |
+ 1 aaaaa |
+ 2 aaaaa |
+ |
+ ]])
end)
it("works with 'number' and 'relativenumber'", function()
@@ -125,12 +155,14 @@ describe('statuscolumn', function()
end)
it("works with highlighted 'statuscolumn'", function()
- command([[set stc=%#NonText#%{&nu?v:lnum:''}]] ..
- [[%=%{&rnu&&(v:lnum%2)?'\ '.v:relnum:''}]] ..
- [[%#LineNr#%{&rnu&&!(v:lnum%2)?'\ '.v:relnum:''}│]])
+ command(
+ [[set stc=%#NonText#%{&nu?v:lnum:''}]]
+ .. [[%=%{&rnu&&(v:lnum%2)?'\ '.v:relnum:''}]]
+ .. [[%#LineNr#%{&rnu&&!(v:lnum%2)?'\ '.v:relnum:''}│]]
+ )
screen:set_default_attr_ids({
- [0] = {bold = true, foreground = Screen.colors.Blue},
- [1] = {foreground = Screen.colors.Brown},
+ [0] = { bold = true, foreground = Screen.colors.Blue },
+ [1] = { foreground = Screen.colors.Brown },
})
screen:expect([[
{0:4 }{1:│}aaaaa |
@@ -188,13 +220,13 @@ describe('statuscolumn', function()
command([[set stc=%C%s%=%{v:virtnum?'':v:lnum}│\ ]])
command("call setline(1,repeat([repeat('aaaaa',10)],16))")
screen:set_default_attr_ids({
- [0] = {bold = true, foreground = Screen.colors.Blue},
- [1] = {foreground = Screen.colors.Brown},
- [2] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGrey},
- [3] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
- [4] = {bold = true, foreground = Screen.colors.Brown},
- [5] = {foreground = Screen.colors.Red},
- [6] = {foreground = Screen.colors.Red, background = Screen.colors.LightGrey},
+ [0] = { bold = true, foreground = Screen.colors.Blue },
+ [1] = { foreground = Screen.colors.Brown },
+ [2] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGrey },
+ [3] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey },
+ [4] = { bold = true, foreground = Screen.colors.Brown },
+ [5] = { foreground = Screen.colors.Red },
+ [6] = { foreground = Screen.colors.Red, background = Screen.colors.LightGrey },
})
command('hi! CursorLine guifg=Red guibg=NONE')
screen:expect([[
@@ -418,7 +450,9 @@ describe('statuscolumn', function()
vim.api.nvim_buf_set_extmark(0, ns, 4, 0, { virt_lines = {{{"virt_line", ""}}} })
]])
command('set foldcolumn=0 signcolumn=no')
- command([[set stc=%{v:virtnum<0?'virtual':(!v:virtnum?'buffer':'wrapped')}%=%{'\ '.v:virtnum.'\ '.v:lnum}]])
+ command(
+ [[set stc=%{v:virtnum<0?'virtual':(!v:virtnum?'buffer':'wrapped')}%=%{'\ '.v:virtnum.'\ '.v:lnum}]]
+ )
screen:expect([[
{1:buffer 0 4}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
{1:wrapped 1 4}aaaaaaaa |
@@ -451,9 +485,7 @@ describe('statuscolumn', function()
{4:wrapped 1 15}{5:aaaaaaaaa^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}|
{4:wrapped 2 15}{5:aaaaaaaaaaaaaaaaaaa }|
{1:virtual-1 15}END |
- {0:~ }|
- {0:~ }|
- {0:~ }|
+ {0:~ }|*3
|
]])
-- Also test virt_lines when 'cpoptions' includes "n"
@@ -478,19 +510,57 @@ describe('statuscolumn', function()
{0:~ }|
|
]])
+ -- Also test "col_rows" code path for 'relativenumber' cursor movement
+ command([[
+ set cpoptions-=n nocursorline relativenumber
+ set stc=%{v:virtnum<0?'virtual':(!v:virtnum?'buffer':'wrapped')}%=%{'\ '.v:virtnum.'\ '.v:lnum.'\ '.v:relnum}
+ ]])
+ screen:expect([[
+ {1:buffer 0 12 3}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 12 3}aaaaaaaaaaa |
+ {1:buffer 0 13 2}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 13 2}aaaaaaaaaaa |
+ {1:buffer 0 14 1}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 14 1}aaaaaaaaaaa |
+ {1:buffer 0 15 0}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 15 0}aaaaaaaaaaa^ aaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 2 15 0}aaaaaaaaaaaaaaaaaaaaaaa |
+ {1:virtual-3 15 0}virt_line1 |
+ {1:virtual-2 15 0}virt_line2 |
+ {1:virtual-1 15 0}END |
+ {0:~ }|
+ |
+ ]])
+ feed('kk')
+ screen:expect([[
+ {1:buffer 0 12 1}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 12 1}aaaaaaaaaaa |
+ {1:buffer 0 13 0}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 13 0}aaaaaaaaaa^a |
+ {1:buffer 0 14 1}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 14 1}aaaaaaaaaaa |
+ {1:buffer 0 15 2}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 1 15 2}aaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaa|
+ {1:wrapped 2 15 2}aaaaaaaaaaaaaaaaaaaaaaa |
+ {1:virtual-3 15 2}virt_line1 |
+ {1:virtual-2 15 2}virt_line2 |
+ {1:virtual-1 15 2}END |
+ {0:~ }|
+ |
+ ]])
end)
it('does not corrupt the screen with minwid sign item', function()
screen:try_resize(screen._width, 3)
screen:set_default_attr_ids({
- [0] = {foreground = Screen.colors.Brown},
- [1] = {foreground = Screen.colors.Blue4, background = Screen.colors.Gray},
+ [0] = { foreground = Screen.colors.Brown },
+ [1] = { foreground = Screen.colors.Blue4, background = Screen.colors.Gray },
})
command([[set stc=%6s\ %l]])
exec_lua('vim.api.nvim_buf_set_extmark(0, ns, 7, 0, {sign_text = "𒀀"})')
screen:expect([[
- {0: 𒀀 8}^aaaaa |
- {0: }{1: }{0: 9}aaaaa |
+ {0: 𒀀 8 }^aaaaa |
+ {0: }{1: }{0: 9 }aaaaa |
|
]])
end)
@@ -511,92 +581,85 @@ describe('statuscolumn', function()
end)
it('clicks work with mousemodel=' .. model, function()
- meths.set_option_value('statuscolumn', '%0@MyClickFunc@%=%l%T', {})
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 1 l 4', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 2 l 4', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 3 l 4', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 0, 0)
- eq('0 4 l 4', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 1 r 7', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 2 r 7', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 3 r 7', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 0)
- eq('0 4 r 7', eval("g:testvar"))
+ api.nvim_set_option_value('statuscolumn', '%0@MyClickFunc@%=%l%T', {})
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 1 l 4', eval('g:testvar'))
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 2 l 4', eval('g:testvar'))
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 3 l 4', eval('g:testvar'))
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
+ eq('0 4 l 4', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 1 r 7', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 2 r 7', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 3 r 7', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 3, 0)
+ eq('0 4 r 7', eval('g:testvar'))
command('rightbelow vsplit')
- meths.input_mouse('left', 'press', '', 0, 0, 27)
- eq('0 1 l 4', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 27)
- eq('0 1 r 7', eval("g:testvar"))
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 27)
+ eq('0 1 l 4', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 3, 27)
+ eq('0 1 r 7', eval('g:testvar'))
command('setlocal rightleft')
- meths.input_mouse('left', 'press', '', 0, 0, 52)
- eq('0 1 l 4', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 52)
- eq('0 1 r 7', eval("g:testvar"))
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 52)
+ eq('0 1 l 4', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 3, 52)
+ eq('0 1 r 7', eval('g:testvar'))
command('wincmd H')
- meths.input_mouse('left', 'press', '', 0, 0, 25)
- eq('0 1 l 4', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 3, 25)
- eq('0 1 r 7', eval("g:testvar"))
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 25)
+ eq('0 1 l 4', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 3, 25)
+ eq('0 1 r 7', eval('g:testvar'))
command('close')
command('set laststatus=2 winbar=%f')
command('let g:testvar = ""')
-- Check that winbar click doesn't register as statuscolumn click
- meths.input_mouse('right', 'press', '', 0, 0, 0)
- eq('', eval("g:testvar"))
+ api.nvim_input_mouse('right', 'press', '', 0, 0, 0)
+ eq('', eval('g:testvar'))
-- Check that statusline click doesn't register as statuscolumn click
- meths.input_mouse('right', 'press', '', 0, 12, 0)
- eq('', eval("g:testvar"))
+ api.nvim_input_mouse('right', 'press', '', 0, 12, 0)
+ eq('', eval('g:testvar'))
-- Check that cmdline click doesn't register as statuscolumn click
- meths.input_mouse('right', 'press', '', 0, 13, 0)
- eq('', eval("g:testvar"))
+ api.nvim_input_mouse('right', 'press', '', 0, 13, 0)
+ eq('', eval('g:testvar'))
end)
it('clicks and highlights work with control characters', function()
- meths.set_option_value('statuscolumn', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {})
- screen:expect{grid=[[
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ api.nvim_set_option_value('statuscolumn', '\t%#NonText#\1%0@MyClickFunc@\t\1%T\t%##\1', {})
+ screen:expect {
+ grid = [[
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |*4
{1:^I}{0:^A^I^A^I}{1:^A}^aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
- {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |
+ {1:^I}{0:^A^I^A^I}{1:^A}aaaaa |*8
|
- ]], attr_ids={
- [0] = {foreground = Screen.colors.Blue, bold = true}; -- NonText
- [1] = {foreground = Screen.colors.Brown}; -- LineNr
- }}
- meths.input_mouse('right', 'press', '', 0, 4, 3)
- eq('', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 5, 8)
- eq('', eval("g:testvar"))
- meths.input_mouse('right', 'press', '', 0, 6, 4)
- eq('0 1 r 10', eval("g:testvar"))
- meths.input_mouse('left', 'press', '', 0, 7, 7)
- eq('0 1 l 11', eval("g:testvar"))
+ ]],
+ attr_ids = {
+ [0] = { foreground = Screen.colors.Blue, bold = true }, -- NonText
+ [1] = { foreground = Screen.colors.Brown }, -- LineNr
+ },
+ }
+ api.nvim_input_mouse('right', 'press', '', 0, 4, 3)
+ eq('', eval('g:testvar'))
+ api.nvim_input_mouse('left', 'press', '', 0, 5, 8)
+ eq('', eval('g:testvar'))
+ api.nvim_input_mouse('right', 'press', '', 0, 6, 4)
+ eq('0 1 r 10', eval('g:testvar'))
+ api.nvim_input_mouse('left', 'press', '', 0, 7, 7)
+ eq('0 1 l 11', eval('g:testvar'))
end)
it('popupmenu callback does not drag mouse on close', function()
screen:try_resize(screen._width, 2)
screen:set_default_attr_ids({
- [0] = {foreground = Screen.colors.Brown},
- [1] = {background = Screen.colors.Plum1},
+ [0] = { foreground = Screen.colors.Brown },
+ [1] = { background = Screen.colors.Plum1 },
})
- meths.set_option_value('statuscolumn', '%0@MyClickFunc@%l%T', {})
+ api.nvim_set_option_value('statuscolumn', '%0@MyClickFunc@%l%T', {})
exec([[
function! MyClickFunc(minwid, clicks, button, mods)
let g:testvar = printf("%d %d %s %d", a:minwid, a:clicks, a:button, getmousepos().line)
@@ -605,26 +668,26 @@ describe('statuscolumn', function()
endfunction
]])
-- clicking an item does not drag mouse
- meths.input_mouse('left', 'press', '', 0, 0, 0)
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
screen:expect([[
{0:8 }^aaaaa |
{1: Echo } |
]])
- meths.input_mouse('left', 'press', '', 0, 1, 5)
- meths.input_mouse('left', 'release', '', 0, 1, 5)
+ api.nvim_input_mouse('left', 'press', '', 0, 1, 5)
+ api.nvim_input_mouse('left', 'release', '', 0, 1, 5)
screen:expect([[
{0:8 }^aaaaa |
0 1 l 8 |
]])
command('echo')
-- clicking outside to close the menu does not drag mouse
- meths.input_mouse('left', 'press', '', 0, 0, 0)
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
screen:expect([[
{0:8 }^aaaaa |
{1: Echo } |
]])
- meths.input_mouse('left', 'press', '', 0, 0, 10)
- meths.input_mouse('left', 'release', '', 0, 0, 10)
+ api.nvim_input_mouse('left', 'press', '', 0, 0, 10)
+ api.nvim_input_mouse('left', 'release', '', 0, 0, 10)
screen:expect([[
{0:8 }^aaaaa |
|
@@ -661,7 +724,9 @@ describe('statuscolumn', function()
it('works with foldcolumn', function()
-- Fits maximum multibyte foldcolumn #21759
command([[set stc=%C%=%l\ fdc=9 fillchars=foldsep:𒀀]])
- for _ = 0,8 do command('norm zfjzo') end
+ for _ = 0, 8 do
+ command('norm zfjzo')
+ end
-- 'statuscolumn' is not drawn for `virt_lines_leftcol` lines
exec_lua([[
vim.api.nvim_buf_set_extmark(0, ns, 6, 0, {
@@ -685,7 +750,7 @@ describe('statuscolumn', function()
14 aaaaa |
|
]])
- command('set stc=') -- also for the default fold column
+ command('set stc=') -- also for the default fold column
screen:expect_unchanged()
-- 'statuscolumn' is not too wide with custom (bogus) fold column
command([[set stc=%{foldlevel(v:lnum)>0?repeat('-',foldlevel(v:lnum)):''}%=%l\ ]])
@@ -702,8 +767,7 @@ describe('statuscolumn', function()
---------8 aaaaa |
virt |
---------9 aaaaa |
- ~ |
- ~ |
+ ~ |*2
|
]])
end)
@@ -718,11 +782,7 @@ describe('statuscolumn', function()
[No Name] [+] |
:1set stc=%^l |
:2 |
- ~ |
- ~ |
- ~ |
- ~ |
- ~ |
+ ~ |*5
[Command Line] |
: |
]])
@@ -749,9 +809,7 @@ describe('statuscolumn', function()
screen:expect([[
aaaaa |
^aaaaa |
- aaaaa |
- aaaaa |
- aaaaa |
+ aaaaa |*3
|
]])
-- width correctly estimated with "w_nrwidth_line_count" when setting 'nu'
@@ -766,7 +824,7 @@ describe('statuscolumn', function()
]])
end)
- it("has correct width with custom sign column when (un)placing signs", function()
+ it('has correct width with custom sign column when (un)placing signs', function()
screen:try_resize(screen._width, 3)
exec_lua([[
vim.cmd.norm('gg')
@@ -823,13 +881,13 @@ describe('statuscolumn', function()
2 ssssaaaaa |
|
]])
- exec_lua("vim.api.nvim_buf_del_extmark(0, ns, id1)")
+ exec_lua('vim.api.nvim_buf_del_extmark(0, ns, id1)')
screen:expect([[
1 ^aaaaa |
2 ssaaaaa |
|
]])
- exec_lua("vim.api.nvim_buf_del_extmark(0, ns, id2)")
+ exec_lua('vim.api.nvim_buf_del_extmark(0, ns, id2)')
screen:expect([[
1 ^aaaaa |
2 aaaaa |
@@ -845,7 +903,7 @@ describe('statuscolumn', function()
]])
end)
- it("is only evaluated twice, once to estimate and once to draw", function()
+ it('is only evaluated twice, once to estimate and once to draw', function()
command([[
let g:stcnr = 0
func! Stc()
@@ -869,4 +927,17 @@ describe('statuscolumn', function()
|
]])
end)
+
+ it('line increase properly redraws buffer text with relativenumber #27709', function()
+ screen:try_resize(33, 4)
+ command([[set rnu nuw=3 stc=%l\ ]])
+ command('call setline(1, range(1, 99))')
+ feed('Gyyp')
+ screen:expect([[
+ 98 98 |
+ 99 99 |
+ 100 ^99 |
+ |
+ ]])
+ end)
end)