aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd/win_scrolled_resized_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/autocmd/win_scrolled_resized_spec.lua')
-rw-r--r--test/functional/autocmd/win_scrolled_resized_spec.lua163
1 files changed, 93 insertions, 70 deletions
diff --git a/test/functional/autocmd/win_scrolled_resized_spec.lua b/test/functional/autocmd/win_scrolled_resized_spec.lua
index e6fdd9560d..d40dc37103 100644
--- a/test/functional/autocmd/win_scrolled_resized_spec.lua
+++ b/test/functional/autocmd/win_scrolled_resized_spec.lua
@@ -7,7 +7,7 @@ local eval = helpers.eval
local exec = helpers.exec
local command = helpers.command
local feed = helpers.feed
-local meths = helpers.meths
+local api = helpers.api
local assert_alive = helpers.assert_alive
before_each(clear)
@@ -32,12 +32,29 @@ describe('WinResized', function()
-- increase window height, two windows will be reported
feed('<C-W>+')
eq(1, eval('g:resized'))
- eq({windows = {1002, 1001}}, eval('g:v_event'))
+ eq({ windows = { 1002, 1001 } }, eval('g:v_event'))
-- increase window width, three windows will be reported
feed('<C-W>>')
eq(2, eval('g:resized'))
- eq({windows = {1002, 1001, 1000}}, eval('g:v_event'))
+ eq({ windows = { 1002, 1001, 1000 } }, eval('g:v_event'))
+ end)
+
+ it('is triggered in terminal mode #21197 #27207', function()
+ exec([[
+ autocmd TermOpen * startinsert
+ let g:resized = 0
+ autocmd WinResized * let g:resized += 1
+ ]])
+ eq(0, eval('g:resized'))
+
+ command('vsplit term://')
+ eq({ mode = 't', blocking = false }, api.nvim_get_mode())
+ eq(1, eval('g:resized'))
+
+ command('split')
+ eq({ mode = 't', blocking = false }, api.nvim_get_mode())
+ eq(2, eval('g:resized'))
end)
end)
@@ -45,7 +62,7 @@ describe('WinScrolled', function()
local win_id
before_each(function()
- win_id = meths.get_current_win().id
+ win_id = api.nvim_get_current_win()
command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id))
exec([[
let g:scrolled = 0
@@ -63,104 +80,104 @@ describe('WinScrolled', function()
end)
it('is triggered by scrolling vertically', function()
- local lines = {'123', '123'}
- meths.buf_set_lines(0, 0, -1, true, lines)
+ local lines = { '123', '123' }
+ api.nvim_buf_set_lines(0, 0, -1, true, lines)
eq(0, eval('g:scrolled'))
feed('<C-E>')
eq(1, eval('g:scrolled'))
eq({
- all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('<C-Y>')
eq(2, eval('g:scrolled'))
eq({
- all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
end)
it('is triggered by scrolling horizontally', function()
command('set nowrap')
- local width = meths.win_get_width(0)
+ local width = api.nvim_win_get_width(0)
local line = '123' .. ('*'):rep(width * 2)
- local lines = {line, line}
- meths.buf_set_lines(0, 0, -1, true, lines)
+ local lines = { line, line }
+ api.nvim_buf_set_lines(0, 0, -1, true, lines)
eq(0, eval('g:scrolled'))
feed('zl')
eq(1, eval('g:scrolled'))
eq({
- all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('zh')
eq(2, eval('g:scrolled'))
eq({
- all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
end)
it('is triggered by horizontal scrolling from cursor move', function()
command('set nowrap')
- local lines = {'', '', 'Foo'}
- meths.buf_set_lines(0, 0, -1, true, lines)
- meths.win_set_cursor(0, {3, 0})
+ local lines = { '', '', 'Foo' }
+ api.nvim_buf_set_lines(0, 0, -1, true, lines)
+ api.nvim_win_set_cursor(0, { 3, 0 })
eq(0, eval('g:scrolled'))
feed('zl')
eq(1, eval('g:scrolled'))
eq({
- all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('zl')
eq(2, eval('g:scrolled'))
eq({
- all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('h')
eq(3, eval('g:scrolled'))
eq({
- all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('zh')
eq(4, eval('g:scrolled'))
eq({
- all = {leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = -1, topline = 0, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
end)
-- oldtest: Test_WinScrolled_long_wrapped()
it('is triggered by scrolling on a long wrapped line #19968', function()
- local height = meths.win_get_height(0)
- local width = meths.win_get_width(0)
- meths.buf_set_lines(0, 0, -1, true, {('foo'):rep(height * width)})
- meths.win_set_cursor(0, {1, height * width - 1})
+ local height = api.nvim_win_get_height(0)
+ local width = api.nvim_win_get_width(0)
+ api.nvim_buf_set_lines(0, 0, -1, true, { ('foo'):rep(height * width) })
+ api.nvim_win_set_cursor(0, { 1, height * width - 1 })
eq(0, eval('g:scrolled'))
feed('gj')
eq(1, eval('g:scrolled'))
eq({
- all = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width},
- ['1000'] = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width},
+ all = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width },
+ ['1000'] = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width },
}, eval('g:v_event'))
feed('0')
eq(2, eval('g:scrolled'))
eq({
- all = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width},
- ['1000'] = {leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = -width},
+ all = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = width },
+ ['1000'] = { leftcol = 0, topline = 0, topfill = 0, width = 0, height = 0, skipcol = -width },
}, eval('g:v_event'))
feed('$')
@@ -168,12 +185,12 @@ describe('WinScrolled', function()
end)
it('is triggered when the window scrolls in Insert mode', function()
- local height = meths.win_get_height(0)
+ local height = api.nvim_win_get_height(0)
local lines = {}
for i = 1, height * 2 do
lines[i] = tostring(i)
end
- meths.buf_set_lines(0, 0, -1, true, lines)
+ api.nvim_buf_set_lines(0, 0, -1, true, lines)
feed('M')
eq(0, eval('g:scrolled'))
@@ -181,15 +198,15 @@ describe('WinScrolled', function()
feed('i<C-X><C-E><Esc>')
eq(1, eval('g:scrolled'))
eq({
- all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('i<C-X><C-Y><Esc>')
eq(2, eval('g:scrolled'))
eq({
- all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = -1, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('L')
@@ -198,8 +215,8 @@ describe('WinScrolled', function()
feed('A<CR><Esc>')
eq(3, eval('g:scrolled'))
eq({
- all = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
end)
end)
@@ -220,12 +237,12 @@ describe('WinScrolled', function()
eq(0, eval('g:scrolled'))
-- With the upper split focused, send a scroll-down event to the unfocused one.
- meths.input_mouse('wheel', 'down', '', 0, 6, 0)
+ api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0)
eq(1, eval('g:scrolled'))
-- Again, but this time while we're in insert mode.
feed('i')
- meths.input_mouse('wheel', 'down', '', 0, 6, 0)
+ api.nvim_input_mouse('wheel', 'down', '', 0, 6, 0)
feed('<Esc>')
eq(2, eval('g:scrolled'))
end)
@@ -257,30 +274,30 @@ describe('WinScrolled', function()
feed('<C-E>')
eq({
- all = {leftcol = 0, topline = 1, topfill = 1, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1001'] = {leftcol = 0, topline = 0, topfill = -1, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 1, topfill = 1, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1001'] = { leftcol = 0, topline = 0, topfill = -1, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('2<C-E>')
eq({
- all = {leftcol = 0, topline = 2, topfill = 2, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1001'] = {leftcol = 0, topline = 0, topfill = -2, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 2, topfill = 2, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1001'] = { leftcol = 0, topline = 0, topfill = -2, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('<C-E>')
eq({
- all = {leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1001'] = {leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 2, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1001'] = { leftcol = 0, topline = 1, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
feed('2<C-Y>')
eq({
- all = {leftcol = 0, topline = 3, topfill = 1, width = 0, height = 0, skipcol = 0},
- ['1000'] = {leftcol = 0, topline = -2, topfill = 0, width = 0, height = 0, skipcol = 0},
- ['1001'] = {leftcol = 0, topline = -1, topfill = 1, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 3, topfill = 1, width = 0, height = 0, skipcol = 0 },
+ ['1000'] = { leftcol = 0, topline = -2, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ ['1001'] = { leftcol = 0, topline = -1, topfill = 1, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
end)
@@ -296,35 +313,41 @@ describe('WinScrolled', function()
]])
eq(0, eval('g:scrolled'))
- local buf = meths.create_buf(true, true)
- meths.buf_set_lines(buf, 0, -1, false, {'@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n'})
- local win = meths.open_win(buf, false, {
+ local buf = api.nvim_create_buf(true, true)
+ api.nvim_buf_set_lines(
+ buf,
+ 0,
+ -1,
+ false,
+ { '@', 'b', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' }
+ )
+ local win = api.nvim_open_win(buf, false, {
height = 5,
width = 10,
col = 0,
row = 1,
relative = 'editor',
- style = 'minimal'
+ style = 'minimal',
})
screen:expect({ any = '@' })
- local winid_str = tostring(win.id)
+ local winid_str = tostring(win)
-- WinScrolled should not be triggered when creating a new floating window
eq(0, eval('g:scrolled'))
- meths.input_mouse('wheel', 'down', '', 0, 3, 3)
+ api.nvim_input_mouse('wheel', 'down', '', 0, 3, 3)
eq(1, eval('g:scrolled'))
eq(winid_str, eval('g:amatch'))
eq({
- all = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0},
- [winid_str] = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ [winid_str] = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
- meths.input_mouse('wheel', 'up', '', 0, 3, 3)
+ api.nvim_input_mouse('wheel', 'up', '', 0, 3, 3)
eq(2, eval('g:scrolled'))
- eq(tostring(win.id), eval('g:amatch'))
+ eq(tostring(win), eval('g:amatch'))
eq({
- all = {leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0},
- [winid_str] = {leftcol = 0, topline = -3, topfill = 0, width = 0, height = 0, skipcol = 0},
+ all = { leftcol = 0, topline = 3, topfill = 0, width = 0, height = 0, skipcol = 0 },
+ [winid_str] = { leftcol = 0, topline = -3, topfill = 0, width = 0, height = 0, skipcol = 0 },
}, eval('g:v_event'))
end)
end)