2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2022-02-14 20:12:09 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2023-07-26 17:38:23 -07:00
|
|
|
local clear, curbuf, curbuf_contents, curwin, eq, neq, matches, ok, feed, insert, eval =
|
2021-09-25 17:48:06 -07:00
|
|
|
helpers.clear,
|
2024-01-12 10:59:57 -07:00
|
|
|
helpers.api.nvim_get_current_buf,
|
2014-10-08 09:56:01 -07:00
|
|
|
helpers.curbuf_contents,
|
2024-01-12 10:59:57 -07:00
|
|
|
helpers.api.nvim_get_current_win,
|
2014-10-08 09:56:01 -07:00
|
|
|
helpers.eq,
|
2021-09-25 17:48:06 -07:00
|
|
|
helpers.neq,
|
2023-07-26 17:38:23 -07:00
|
|
|
helpers.matches,
|
2021-09-25 17:48:06 -07:00
|
|
|
helpers.ok,
|
|
|
|
helpers.feed,
|
|
|
|
helpers.insert,
|
2024-01-12 06:11:28 -07:00
|
|
|
helpers.eval
|
2020-10-19 11:17:51 -07:00
|
|
|
local poke_eventloop = helpers.poke_eventloop
|
2022-12-10 05:13:40 -07:00
|
|
|
local exec = helpers.exec
|
2023-07-26 17:38:23 -07:00
|
|
|
local exec_lua = helpers.exec_lua
|
2024-01-12 10:59:57 -07:00
|
|
|
local fn = helpers.fn
|
2016-09-14 02:17:07 -07:00
|
|
|
local request = helpers.request
|
2024-01-12 04:28:20 -07:00
|
|
|
local NIL = vim.NIL
|
2024-01-12 10:59:57 -07:00
|
|
|
local api = helpers.api
|
2017-02-22 15:34:25 -07:00
|
|
|
local command = helpers.command
|
2019-09-03 13:51:45 -07:00
|
|
|
local pcall_err = helpers.pcall_err
|
2021-09-25 17:48:06 -07:00
|
|
|
local assert_alive = helpers.assert_alive
|
2014-10-26 08:10:36 -07:00
|
|
|
|
2018-11-25 08:27:10 -07:00
|
|
|
describe('API/win', function()
|
2014-10-08 09:56:01 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
2016-09-16 21:30:36 -07:00
|
|
|
describe('get_buf', function()
|
2014-10-08 09:56:01 -07:00
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(curbuf(), api.nvim_win_get_buf(api.nvim_list_wins()[1]))
|
2024-01-12 06:11:28 -07:00
|
|
|
command('new')
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_current_win(api.nvim_list_wins()[2])
|
|
|
|
eq(curbuf(), api.nvim_win_get_buf(api.nvim_list_wins()[2]))
|
2024-01-12 06:11:28 -07:00
|
|
|
neq(
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_get_buf(api.nvim_list_wins()[1]),
|
|
|
|
api.nvim_win_get_buf(api.nvim_list_wins()[2])
|
2024-01-12 06:11:28 -07:00
|
|
|
)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2018-11-25 08:27:10 -07:00
|
|
|
describe('set_buf', function()
|
|
|
|
it('works', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('new')
|
2024-01-12 10:59:57 -07:00
|
|
|
local windows = api.nvim_list_wins()
|
|
|
|
neq(api.nvim_win_get_buf(windows[2]), api.nvim_win_get_buf(windows[1]))
|
|
|
|
api.nvim_win_set_buf(windows[2], api.nvim_win_get_buf(windows[1]))
|
|
|
|
eq(api.nvim_win_get_buf(windows[2]), api.nvim_win_get_buf(windows[1]))
|
2018-11-25 08:27:10 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('validates args', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('Invalid buffer id: 23', pcall_err(api.nvim_win_set_buf, api.nvim_get_current_win(), 23))
|
|
|
|
eq('Invalid window id: 23', pcall_err(api.nvim_win_set_buf, 23, api.nvim_get_current_buf()))
|
2018-11-25 08:27:10 -07:00
|
|
|
end)
|
2023-07-23 11:50:20 -07:00
|
|
|
|
2023-07-26 17:38:23 -07:00
|
|
|
it('disallowed in cmdwin if win=cmdwin_{old_cur}win or buf=cmdwin_buf', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local new_buf = api.nvim_create_buf(true, true)
|
|
|
|
local old_win = api.nvim_get_current_win()
|
|
|
|
local new_win = api.nvim_open_win(new_buf, false, {
|
2023-07-23 11:50:20 -07:00
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
width = 50,
|
|
|
|
height = 10,
|
|
|
|
})
|
|
|
|
feed('q:')
|
|
|
|
eq(
|
|
|
|
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_set_buf, 0, new_buf)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-08-16 16:53:10 -07:00
|
|
|
eq(
|
|
|
|
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_set_buf, old_win, new_buf)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-23 11:50:20 -07:00
|
|
|
eq(
|
|
|
|
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_set_buf, new_win, 0)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-26 17:38:23 -07:00
|
|
|
matches(
|
|
|
|
'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$',
|
|
|
|
pcall_err(
|
|
|
|
exec_lua,
|
|
|
|
[[
|
|
|
|
local cmdwin_buf = vim.api.nvim_get_current_buf()
|
|
|
|
local new_win, new_buf = ...
|
|
|
|
vim.api.nvim_buf_call(new_buf, function()
|
|
|
|
vim.api.nvim_win_set_buf(new_win, cmdwin_buf)
|
|
|
|
end)
|
|
|
|
]],
|
|
|
|
new_win,
|
|
|
|
new_buf
|
|
|
|
)
|
|
|
|
)
|
|
|
|
matches(
|
|
|
|
'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$',
|
|
|
|
pcall_err(
|
|
|
|
exec_lua,
|
|
|
|
[[
|
|
|
|
local cmdwin_win = vim.api.nvim_get_current_win()
|
|
|
|
local new_win, new_buf = ...
|
|
|
|
vim.api.nvim_win_call(new_win, function()
|
|
|
|
vim.api.nvim_win_set_buf(cmdwin_win, new_buf)
|
|
|
|
end)
|
|
|
|
]],
|
|
|
|
new_win,
|
|
|
|
new_buf
|
|
|
|
)
|
|
|
|
)
|
2023-07-23 11:50:20 -07:00
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
local next_buf = api.nvim_create_buf(true, true)
|
|
|
|
api.nvim_win_set_buf(new_win, next_buf)
|
|
|
|
eq(next_buf, api.nvim_win_get_buf(new_win))
|
2023-07-23 11:50:20 -07:00
|
|
|
end)
|
2018-11-25 08:27:10 -07:00
|
|
|
end)
|
|
|
|
|
2014-10-08 09:56:01 -07:00
|
|
|
describe('{get,set}_cursor', function()
|
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 1, 0 }, api.nvim_win_get_cursor(0))
|
2024-01-12 06:11:28 -07:00
|
|
|
command('normal ityping\027o some text')
|
2014-10-08 09:56:01 -07:00
|
|
|
eq('typing\n some text', curbuf_contents())
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 2, 10 }, api.nvim_win_get_cursor(0))
|
|
|
|
api.nvim_win_set_cursor(0, { 2, 6 })
|
2024-01-12 06:11:28 -07:00
|
|
|
command('normal i dumb')
|
2014-10-08 09:56:01 -07:00
|
|
|
eq('typing\n some dumb text', curbuf_contents())
|
|
|
|
end)
|
2014-10-26 08:10:36 -07:00
|
|
|
|
2022-02-14 20:12:09 -07:00
|
|
|
it('does not leak memory when using invalid window ID with invalid pos', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('Invalid window id: 1', pcall_err(api.nvim_win_set_cursor, 1, { 'b\na' }))
|
2017-05-08 11:06:23 -07:00
|
|
|
end)
|
|
|
|
|
2014-10-26 08:10:36 -07:00
|
|
|
it('updates the screen, and also when the window is unfocused', function()
|
2022-10-05 02:23:11 -07:00
|
|
|
local screen = Screen.new(30, 9)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[1] = { bold = true, foreground = Screen.colors.Blue },
|
|
|
|
[2] = { bold = true, reverse = true },
|
|
|
|
[3] = { reverse = true },
|
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
|
2014-10-26 08:10:36 -07:00
|
|
|
insert('prologue')
|
|
|
|
feed('100o<esc>')
|
|
|
|
insert('epilogue')
|
2015-11-17 15:31:22 -07:00
|
|
|
local win = curwin()
|
2014-10-26 08:10:36 -07:00
|
|
|
feed('gg')
|
|
|
|
|
2022-10-05 02:23:11 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
^prologue |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*8
|
2022-10-05 02:23:11 -07:00
|
|
|
]],
|
|
|
|
}
|
2014-10-26 08:10:36 -07:00
|
|
|
-- cursor position is at beginning
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 1, 0 }, api.nvim_win_get_cursor(win))
|
2014-10-26 08:10:36 -07:00
|
|
|
|
|
|
|
-- move cursor to end
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_cursor(win, { 101, 0 })
|
2022-10-05 02:23:11 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2023-12-09 05:42:00 -07:00
|
|
|
|*7
|
2022-10-05 02:23:11 -07:00
|
|
|
^epilogue |
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
2014-10-26 08:10:36 -07:00
|
|
|
|
|
|
|
-- move cursor to the beginning again
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_cursor(win, { 1, 0 })
|
2022-10-05 02:23:11 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
^prologue |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*8
|
2022-10-05 02:23:11 -07:00
|
|
|
]],
|
|
|
|
}
|
2014-10-26 08:10:36 -07:00
|
|
|
|
|
|
|
-- move focus to new window
|
2024-01-12 06:11:28 -07:00
|
|
|
command('new')
|
2014-10-26 08:10:36 -07:00
|
|
|
neq(win, curwin())
|
|
|
|
|
|
|
|
-- sanity check, cursor position is kept
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 1, 0 }, api.nvim_win_get_cursor(win))
|
2022-10-05 02:23:11 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2022-10-05 02:23:11 -07:00
|
|
|
{2:[No Name] }|
|
|
|
|
prologue |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*2
|
2022-10-05 02:23:11 -07:00
|
|
|
{3:[No Name] [+] }|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
2014-10-26 08:10:36 -07:00
|
|
|
|
|
|
|
-- move cursor to end
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_cursor(win, { 101, 0 })
|
2022-10-05 02:23:11 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2022-10-05 02:23:11 -07:00
|
|
|
{2:[No Name] }|
|
2023-12-09 05:42:00 -07:00
|
|
|
|*2
|
2022-10-05 02:23:11 -07:00
|
|
|
epilogue |
|
|
|
|
{3:[No Name] [+] }|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
2014-10-26 08:10:36 -07:00
|
|
|
|
|
|
|
-- move cursor to the beginning again
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_cursor(win, { 1, 0 })
|
2022-10-05 02:23:11 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
^ |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }|*2
|
2022-10-05 02:23:11 -07:00
|
|
|
{2:[No Name] }|
|
|
|
|
prologue |
|
2023-12-09 05:42:00 -07:00
|
|
|
|*2
|
2022-10-05 02:23:11 -07:00
|
|
|
{3:[No Name] [+] }|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
2014-10-26 08:10:36 -07:00
|
|
|
|
|
|
|
-- curwin didn't change back
|
|
|
|
neq(win, curwin())
|
|
|
|
end)
|
|
|
|
|
2018-06-24 17:14:55 -07:00
|
|
|
it('remembers what column it wants to be in', function()
|
|
|
|
insert('first line')
|
|
|
|
feed('o<esc>')
|
|
|
|
insert('second line')
|
|
|
|
|
|
|
|
feed('gg')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop() -- let nvim process the 'gg' command
|
2018-06-24 17:14:55 -07:00
|
|
|
|
|
|
|
-- cursor position is at beginning
|
|
|
|
local win = curwin()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 1, 0 }, api.nvim_win_get_cursor(win))
|
2018-06-24 17:14:55 -07:00
|
|
|
|
|
|
|
-- move cursor to column 5
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_cursor(win, { 1, 5 })
|
2018-06-24 17:14:55 -07:00
|
|
|
|
|
|
|
-- move down a line
|
|
|
|
feed('j')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop() -- let nvim process the 'j' command
|
2018-06-24 17:14:55 -07:00
|
|
|
|
|
|
|
-- cursor is still in column 5
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 2, 5 }, api.nvim_win_get_cursor(win))
|
2018-06-24 17:14:55 -07:00
|
|
|
end)
|
|
|
|
|
2022-02-14 20:12:09 -07:00
|
|
|
it('updates cursorline and statusline ruler in non-current window', function()
|
|
|
|
local screen = Screen.new(60, 8)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[1] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
|
|
|
|
[2] = { background = Screen.colors.Grey90 }, -- CursorLine
|
|
|
|
[3] = { bold = true, reverse = true }, -- StatusLine
|
|
|
|
[4] = { reverse = true }, -- StatusLineNC
|
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
command('set ruler')
|
|
|
|
command('set cursorline')
|
|
|
|
insert([[
|
|
|
|
aaa
|
|
|
|
bbb
|
|
|
|
ccc
|
|
|
|
ddd]])
|
|
|
|
local oldwin = curwin()
|
|
|
|
command('vsplit')
|
|
|
|
screen:expect([[
|
2022-05-15 09:34:44 -07:00
|
|
|
aaa │aaa |
|
|
|
|
bbb │bbb |
|
|
|
|
ccc │ccc |
|
|
|
|
{2:dd^d }│{2:ddd }|
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }│{1:~ }|*2
|
2022-02-14 20:12:09 -07:00
|
|
|
{3:[No Name] [+] 4,3 All }{4:[No Name] [+] 4,3 All}|
|
|
|
|
|
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_cursor(oldwin, { 1, 0 })
|
2022-02-14 20:12:09 -07:00
|
|
|
screen:expect([[
|
2022-05-15 09:34:44 -07:00
|
|
|
aaa │{2:aaa }|
|
|
|
|
bbb │bbb |
|
|
|
|
ccc │ccc |
|
|
|
|
{2:dd^d }│ddd |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }│{1:~ }|*2
|
2022-02-14 20:12:09 -07:00
|
|
|
{3:[No Name] [+] 4,3 All }{4:[No Name] [+] 1,1 All}|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2022-11-16 16:18:31 -07:00
|
|
|
|
|
|
|
it('updates cursorcolumn in non-current window', function()
|
|
|
|
local screen = Screen.new(60, 8)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[1] = { bold = true, foreground = Screen.colors.Blue }, -- NonText
|
|
|
|
[2] = { background = Screen.colors.Grey90 }, -- CursorColumn
|
|
|
|
[3] = { bold = true, reverse = true }, -- StatusLine
|
|
|
|
[4] = { reverse = true }, -- StatusLineNC
|
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
command('set cursorcolumn')
|
|
|
|
insert([[
|
|
|
|
aaa
|
|
|
|
bbb
|
|
|
|
ccc
|
|
|
|
ddd]])
|
|
|
|
local oldwin = curwin()
|
|
|
|
command('vsplit')
|
|
|
|
screen:expect([[
|
|
|
|
aa{2:a} │aa{2:a} |
|
|
|
|
bb{2:b} │bb{2:b} |
|
|
|
|
cc{2:c} │cc{2:c} |
|
|
|
|
dd^d │ddd |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }│{1:~ }|*2
|
2022-11-16 16:18:31 -07:00
|
|
|
{3:[No Name] [+] }{4:[No Name] [+] }|
|
|
|
|
|
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_cursor(oldwin, { 2, 0 })
|
2022-11-16 16:18:31 -07:00
|
|
|
screen:expect([[
|
|
|
|
aa{2:a} │{2:a}aa |
|
|
|
|
bb{2:b} │bbb |
|
|
|
|
cc{2:c} │{2:c}cc |
|
|
|
|
dd^d │{2:d}dd |
|
2023-12-09 05:42:00 -07:00
|
|
|
{1:~ }│{1:~ }|*2
|
2022-11-16 16:18:31 -07:00
|
|
|
{3:[No Name] [+] }{4:[No Name] [+] }|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('{get,set}_height', function()
|
|
|
|
it('works', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('vsplit')
|
|
|
|
eq(
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_get_height(api.nvim_list_wins()[2]),
|
|
|
|
api.nvim_win_get_height(api.nvim_list_wins()[1])
|
2024-01-12 06:11:28 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_current_win(api.nvim_list_wins()[2])
|
2024-01-12 06:11:28 -07:00
|
|
|
command('split')
|
2016-09-16 21:30:36 -07:00
|
|
|
eq(
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_get_height(api.nvim_list_wins()[2]),
|
|
|
|
math.floor(api.nvim_win_get_height(api.nvim_list_wins()[1]) / 2)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_height(api.nvim_list_wins()[2], 2)
|
|
|
|
eq(2, api.nvim_win_get_height(api.nvim_list_wins()[2]))
|
2023-06-01 03:23:42 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('correctly handles height=1', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_current_win(api.nvim_list_wins()[1])
|
|
|
|
api.nvim_win_set_height(api.nvim_list_wins()[2], 1)
|
|
|
|
eq(1, api.nvim_win_get_height(api.nvim_list_wins()[2]))
|
2023-06-01 03:23:42 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('correctly handles height=1 with a winbar', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('set winbar=foobar')
|
|
|
|
command('set winminheight=0')
|
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_current_win(api.nvim_list_wins()[1])
|
|
|
|
api.nvim_win_set_height(api.nvim_list_wins()[2], 1)
|
|
|
|
eq(1, api.nvim_win_get_height(api.nvim_list_wins()[2]))
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
2022-12-10 05:13:40 -07:00
|
|
|
|
|
|
|
it('do not cause ml_get errors with foldmethod=expr #19989', function()
|
|
|
|
insert([[
|
|
|
|
aaaaa
|
|
|
|
bbbbb
|
|
|
|
ccccc]])
|
|
|
|
command('set foldmethod=expr')
|
|
|
|
exec([[
|
|
|
|
new
|
|
|
|
let w = nvim_get_current_win()
|
|
|
|
wincmd w
|
|
|
|
call nvim_win_set_height(w, 5)
|
|
|
|
]])
|
|
|
|
feed('l')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', api.nvim_get_vvar('errmsg'))
|
2022-12-10 05:13:40 -07:00
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('{get,set}_width', function()
|
|
|
|
it('works', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('split')
|
|
|
|
eq(
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_get_width(api.nvim_list_wins()[2]),
|
|
|
|
api.nvim_win_get_width(api.nvim_list_wins()[1])
|
2024-01-12 06:11:28 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_current_win(api.nvim_list_wins()[2])
|
2024-01-12 06:11:28 -07:00
|
|
|
command('vsplit')
|
2016-09-16 21:30:36 -07:00
|
|
|
eq(
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_get_width(api.nvim_list_wins()[2]),
|
|
|
|
math.floor(api.nvim_win_get_width(api.nvim_list_wins()[1]) / 2)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_width(api.nvim_list_wins()[2], 2)
|
|
|
|
eq(2, api.nvim_win_get_width(api.nvim_list_wins()[2]))
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
2022-12-10 05:13:40 -07:00
|
|
|
|
|
|
|
it('do not cause ml_get errors with foldmethod=expr #19989', function()
|
|
|
|
insert([[
|
|
|
|
aaaaa
|
|
|
|
bbbbb
|
|
|
|
ccccc]])
|
|
|
|
command('set foldmethod=expr')
|
|
|
|
exec([[
|
|
|
|
vnew
|
|
|
|
let w = nvim_get_current_win()
|
|
|
|
wincmd w
|
|
|
|
call nvim_win_set_width(w, 5)
|
|
|
|
]])
|
|
|
|
feed('l')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', api.nvim_get_vvar('errmsg'))
|
2022-12-10 05:13:40 -07:00
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
2016-02-10 16:01:17 -07:00
|
|
|
describe('{get,set,del}_var', function()
|
2014-10-08 09:56:01 -07:00
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } })
|
|
|
|
eq({ 1, 2, { ['3'] = 1 } }, api.nvim_win_get_var(0, 'lua'))
|
|
|
|
eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('w:lua'))
|
|
|
|
eq(1, fn.exists('w:lua'))
|
|
|
|
api.nvim_win_del_var(0, 'lua')
|
|
|
|
eq(0, fn.exists('w:lua'))
|
|
|
|
eq('Key not found: lua', pcall_err(api.nvim_win_del_var, 0, 'lua'))
|
|
|
|
api.nvim_win_set_var(0, 'lua', 1)
|
2017-02-22 15:34:25 -07:00
|
|
|
command('lockvar w:lua')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('Key is locked: lua', pcall_err(api.nvim_win_del_var, 0, 'lua'))
|
|
|
|
eq('Key is locked: lua', pcall_err(api.nvim_win_set_var, 0, 'lua', 1))
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
2016-09-14 02:17:07 -07:00
|
|
|
|
|
|
|
it('window_set_var returns the old value', function()
|
|
|
|
local val1 = { 1, 2, { ['3'] = 1 } }
|
|
|
|
local val2 = { 4, 7 }
|
|
|
|
eq(NIL, request('window_set_var', 0, 'lua', val1))
|
|
|
|
eq(val1, request('window_set_var', 0, 'lua', val2))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('window_del_var returns the old value', function()
|
|
|
|
local val1 = { 1, 2, { ['3'] = 1 } }
|
|
|
|
local val2 = { 4, 7 }
|
|
|
|
eq(NIL, request('window_set_var', 0, 'lua', val1))
|
|
|
|
eq(val1, request('window_set_var', 0, 'lua', val2))
|
|
|
|
eq(val2, request('window_del_var', 0, 'lua'))
|
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
2022-12-19 09:37:45 -07:00
|
|
|
describe('nvim_get_option_value, nvim_set_option_value', function()
|
2014-10-08 09:56:01 -07:00
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('colorcolumn', '4,3', {})
|
|
|
|
eq('4,3', api.nvim_get_option_value('colorcolumn', {}))
|
2019-09-01 19:38:50 -07:00
|
|
|
command('set modified hidden')
|
|
|
|
command('enew') -- edit new buffer, window option is preserved
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('4,3', api.nvim_get_option_value('colorcolumn', {}))
|
2019-09-01 19:38:50 -07:00
|
|
|
|
2014-10-08 09:56:01 -07:00
|
|
|
-- global-local option
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('statusline', 'window-status', { win = 0 })
|
|
|
|
eq('window-status', api.nvim_get_option_value('statusline', { win = 0 }))
|
|
|
|
eq('', api.nvim_get_option_value('statusline', { scope = 'global' }))
|
2019-09-01 19:38:50 -07:00
|
|
|
command('set modified')
|
|
|
|
command('enew') -- global-local: not preserved in new buffer
|
2021-10-11 21:09:08 -07:00
|
|
|
-- confirm local value was not copied
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('', api.nvim_get_option_value('statusline', { win = 0 }))
|
2021-10-11 21:09:08 -07:00
|
|
|
eq('', eval('&l:statusline'))
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
2021-09-25 17:48:06 -07:00
|
|
|
|
|
|
|
it('after switching windows #15390', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('tabnew')
|
2024-01-12 10:59:57 -07:00
|
|
|
local tab1 = unpack(api.nvim_list_tabpages())
|
|
|
|
local win1 = unpack(api.nvim_tabpage_list_wins(tab1))
|
2024-01-16 06:26:21 -07:00
|
|
|
api.nvim_set_option_value('statusline', 'window-status', { win = win1 })
|
2024-01-12 06:11:28 -07:00
|
|
|
command('split')
|
|
|
|
command('wincmd J')
|
|
|
|
command('wincmd j')
|
2024-01-16 06:26:21 -07:00
|
|
|
eq('window-status', api.nvim_get_option_value('statusline', { win = win1 }))
|
2021-09-25 17:48:06 -07:00
|
|
|
assert_alive()
|
|
|
|
end)
|
2021-10-11 21:09:08 -07:00
|
|
|
|
|
|
|
it('returns values for unset local options', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(-1, api.nvim_get_option_value('scrolloff', { win = 0, scope = 'local' }))
|
2021-10-11 21:09:08 -07:00
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('get_position', function()
|
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local height = api.nvim_win_get_height(api.nvim_list_wins()[1])
|
|
|
|
local width = api.nvim_win_get_width(api.nvim_list_wins()[1])
|
2024-01-12 06:11:28 -07:00
|
|
|
command('split')
|
|
|
|
command('vsplit')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ 0, 0 }, api.nvim_win_get_position(api.nvim_list_wins()[1]))
|
2014-10-08 09:56:01 -07:00
|
|
|
local vsplit_pos = math.floor(width / 2)
|
|
|
|
local split_pos = math.floor(height / 2)
|
2024-01-12 10:59:57 -07:00
|
|
|
local win2row, win2col = unpack(api.nvim_win_get_position(api.nvim_list_wins()[2]))
|
|
|
|
local win3row, win3col = unpack(api.nvim_win_get_position(api.nvim_list_wins()[3]))
|
2014-10-08 09:56:01 -07:00
|
|
|
eq(0, win2row)
|
|
|
|
eq(0, win3col)
|
|
|
|
ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1)
|
|
|
|
ok(split_pos - 1 <= win3row and win3row <= split_pos + 1)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('get_position', function()
|
|
|
|
it('works', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('tabnew')
|
|
|
|
command('vsplit')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[1]), api.nvim_list_tabpages()[1])
|
|
|
|
eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[2]), api.nvim_list_tabpages()[2])
|
|
|
|
eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[3]), api.nvim_list_tabpages()[2])
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2016-10-03 20:36:47 -07:00
|
|
|
describe('get_number', function()
|
|
|
|
it('works', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local wins = api.nvim_list_wins()
|
|
|
|
eq(1, api.nvim_win_get_number(wins[1]))
|
2016-10-03 20:36:47 -07:00
|
|
|
|
2024-01-12 06:11:28 -07:00
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
local win1, win2 = unpack(api.nvim_list_wins())
|
|
|
|
eq(1, api.nvim_win_get_number(win1))
|
|
|
|
eq(2, api.nvim_win_get_number(win2))
|
2016-10-03 20:36:47 -07:00
|
|
|
|
2024-01-12 06:11:28 -07:00
|
|
|
command('wincmd J')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, api.nvim_win_get_number(win1))
|
|
|
|
eq(1, api.nvim_win_get_number(win2))
|
2016-10-03 20:36:47 -07:00
|
|
|
|
2024-01-12 06:11:28 -07:00
|
|
|
command('tabnew')
|
2024-01-12 10:59:57 -07:00
|
|
|
local win3 = api.nvim_list_wins()[3]
|
2016-10-03 20:36:47 -07:00
|
|
|
-- First tab page
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, api.nvim_win_get_number(win1))
|
|
|
|
eq(1, api.nvim_win_get_number(win2))
|
2016-10-03 20:36:47 -07:00
|
|
|
-- Second tab page
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, api.nvim_win_get_number(win3))
|
2016-10-03 20:36:47 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2014-10-08 09:56:01 -07:00
|
|
|
describe('is_valid', function()
|
|
|
|
it('works', function()
|
2024-01-12 06:11:28 -07:00
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
local win = api.nvim_list_wins()[2]
|
|
|
|
api.nvim_set_current_win(win)
|
|
|
|
ok(api.nvim_win_is_valid(win))
|
2024-01-12 06:11:28 -07:00
|
|
|
command('close')
|
2024-01-12 10:59:57 -07:00
|
|
|
ok(not api.nvim_win_is_valid(win))
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
end)
|
2019-03-03 02:26:11 -07:00
|
|
|
|
|
|
|
describe('close', function()
|
|
|
|
it('can close current window', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
2019-03-03 02:26:11 -07:00
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
local newwin = api.nvim_get_current_win()
|
|
|
|
api.nvim_win_close(newwin, false)
|
|
|
|
eq({ oldwin }, api.nvim_list_wins())
|
2019-03-03 02:26:11 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('can close noncurrent window', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
2019-03-03 02:26:11 -07:00
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
local newwin = api.nvim_get_current_win()
|
|
|
|
api.nvim_win_close(oldwin, false)
|
|
|
|
eq({ newwin }, api.nvim_list_wins())
|
2019-03-03 02:26:11 -07:00
|
|
|
end)
|
|
|
|
|
2021-08-17 20:30:58 -07:00
|
|
|
it("handles changed buffer when 'hidden' is unset", function()
|
|
|
|
command('set nohidden')
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
2019-03-03 02:26:11 -07:00
|
|
|
insert('text')
|
|
|
|
command('new')
|
2024-01-12 10:59:57 -07:00
|
|
|
local newwin = api.nvim_get_current_win()
|
2019-09-03 13:51:45 -07:00
|
|
|
eq(
|
|
|
|
'Vim:E37: No write since last change (add ! to override)',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_close, oldwin, false)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ newwin, oldwin }, api.nvim_list_wins())
|
2019-03-03 02:26:11 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles changed buffer with force', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
2019-03-03 02:26:11 -07:00
|
|
|
insert('text')
|
|
|
|
command('new')
|
2024-01-12 10:59:57 -07:00
|
|
|
local newwin = api.nvim_get_current_win()
|
|
|
|
api.nvim_win_close(oldwin, true)
|
|
|
|
eq({ newwin }, api.nvim_list_wins())
|
2019-03-03 02:26:11 -07:00
|
|
|
end)
|
2019-08-10 04:41:35 -07:00
|
|
|
|
|
|
|
it('in cmdline-window #9767', function()
|
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(2, #api.nvim_list_wins())
|
2023-07-26 17:38:23 -07:00
|
|
|
local oldbuf = api.nvim_get_current_buf()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
|
|
|
local otherwin = api.nvim_open_win(0, false, {
|
2023-07-23 15:10:28 -07:00
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
})
|
2019-08-10 04:41:35 -07:00
|
|
|
-- Open cmdline-window.
|
|
|
|
feed('q:')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(4, #api.nvim_list_wins())
|
|
|
|
eq(':', fn.getcmdwintype())
|
2023-07-23 15:10:28 -07:00
|
|
|
-- Not allowed to close previous window from cmdline-window.
|
2019-09-06 17:17:37 -07:00
|
|
|
eq(
|
|
|
|
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_close, oldwin, true)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-23 15:10:28 -07:00
|
|
|
-- Closing other windows is fine.
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_close(otherwin, true)
|
|
|
|
eq(false, api.nvim_win_is_valid(otherwin))
|
2019-08-10 04:41:35 -07:00
|
|
|
-- Close cmdline-window.
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_close(0, true)
|
|
|
|
eq(2, #api.nvim_list_wins())
|
|
|
|
eq('', fn.getcmdwintype())
|
2023-07-26 17:38:23 -07:00
|
|
|
|
|
|
|
-- Closing curwin in context of a different window shouldn't close cmdwin.
|
|
|
|
otherwin = api.nvim_open_win(0, false, {
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
})
|
|
|
|
feed('q:')
|
|
|
|
exec_lua(
|
|
|
|
[[
|
|
|
|
vim.api.nvim_win_call(..., function()
|
|
|
|
vim.api.nvim_win_close(0, true)
|
|
|
|
end)
|
|
|
|
]],
|
|
|
|
otherwin
|
|
|
|
)
|
|
|
|
eq(false, api.nvim_win_is_valid(otherwin))
|
|
|
|
eq(':', fn.getcmdwintype())
|
|
|
|
-- Closing cmdwin in context of a non-previous window is still OK.
|
|
|
|
otherwin = api.nvim_open_win(oldbuf, false, {
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
})
|
|
|
|
exec_lua(
|
|
|
|
[[
|
|
|
|
local otherwin, cmdwin = ...
|
|
|
|
vim.api.nvim_win_call(otherwin, function()
|
|
|
|
vim.api.nvim_win_close(cmdwin, true)
|
|
|
|
end)
|
|
|
|
]],
|
|
|
|
otherwin,
|
|
|
|
api.nvim_get_current_win()
|
|
|
|
)
|
|
|
|
eq('', fn.getcmdwintype())
|
|
|
|
eq(true, api.nvim_win_is_valid(otherwin))
|
2019-08-10 04:41:35 -07:00
|
|
|
end)
|
2021-08-22 15:27:20 -07:00
|
|
|
|
|
|
|
it('closing current (float) window of another tabpage #15313', function()
|
|
|
|
command('tabedit')
|
2022-12-01 19:30:50 -07:00
|
|
|
command('botright split')
|
2024-01-16 06:26:21 -07:00
|
|
|
local prevwin = curwin()
|
2021-08-22 15:27:20 -07:00
|
|
|
eq(2, eval('tabpagenr()'))
|
2024-01-12 10:59:57 -07:00
|
|
|
local win = api.nvim_open_win(0, true, {
|
2021-08-22 15:27:20 -07:00
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
width = 50,
|
|
|
|
height = 10,
|
|
|
|
})
|
2021-09-25 17:48:06 -07:00
|
|
|
local tab = eval('tabpagenr()')
|
2021-08-22 15:27:20 -07:00
|
|
|
command('tabprevious')
|
|
|
|
eq(1, eval('tabpagenr()'))
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_close(win, false)
|
2021-08-22 15:27:20 -07:00
|
|
|
|
2024-01-16 06:26:21 -07:00
|
|
|
eq(prevwin, api.nvim_tabpage_get_win(tab))
|
2021-09-25 17:48:06 -07:00
|
|
|
assert_alive()
|
2021-08-22 15:27:20 -07:00
|
|
|
end)
|
2019-03-03 02:26:11 -07:00
|
|
|
end)
|
2021-03-09 20:21:45 -07:00
|
|
|
|
|
|
|
describe('hide', function()
|
|
|
|
it('can hide current window', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
2021-03-09 20:21:45 -07:00
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
local newwin = api.nvim_get_current_win()
|
|
|
|
api.nvim_win_hide(newwin)
|
|
|
|
eq({ oldwin }, api.nvim_list_wins())
|
2021-03-09 20:21:45 -07:00
|
|
|
end)
|
|
|
|
it('can hide noncurrent window', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
2021-03-09 20:21:45 -07:00
|
|
|
command('split')
|
2024-01-12 10:59:57 -07:00
|
|
|
local newwin = api.nvim_get_current_win()
|
|
|
|
api.nvim_win_hide(oldwin)
|
|
|
|
eq({ newwin }, api.nvim_list_wins())
|
2021-03-09 20:21:45 -07:00
|
|
|
end)
|
|
|
|
it('does not close the buffer', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
|
|
|
local oldbuf = api.nvim_get_current_buf()
|
|
|
|
local buf = api.nvim_create_buf(true, false)
|
|
|
|
local newwin = api.nvim_open_win(buf, true, {
|
2021-03-09 20:21:45 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_hide(newwin)
|
|
|
|
eq({ oldwin }, api.nvim_list_wins())
|
|
|
|
eq({ oldbuf, buf }, api.nvim_list_bufs())
|
2021-03-09 20:21:45 -07:00
|
|
|
end)
|
|
|
|
it('deletes the buffer when bufhidden=wipe', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local oldwin = api.nvim_get_current_win()
|
|
|
|
local oldbuf = api.nvim_get_current_buf()
|
2024-01-16 06:26:21 -07:00
|
|
|
local buf = api.nvim_create_buf(true, false)
|
2024-01-12 10:59:57 -07:00
|
|
|
local newwin = api.nvim_open_win(buf, true, {
|
2021-03-09 20:21:45 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('bufhidden', 'wipe', { buf = buf })
|
|
|
|
api.nvim_win_hide(newwin)
|
|
|
|
eq({ oldwin }, api.nvim_list_wins())
|
|
|
|
eq({ oldbuf }, api.nvim_list_bufs())
|
2021-03-09 20:21:45 -07:00
|
|
|
end)
|
2023-07-24 06:19:01 -07:00
|
|
|
it('in the cmdwin', function()
|
|
|
|
feed('q:')
|
|
|
|
-- Can close the cmdwin.
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_hide(0)
|
|
|
|
eq('', fn.getcmdwintype())
|
2023-07-24 06:19:01 -07:00
|
|
|
|
2023-07-26 17:38:23 -07:00
|
|
|
local old_buf = api.nvim_get_current_buf()
|
2024-01-12 10:59:57 -07:00
|
|
|
local old_win = api.nvim_get_current_win()
|
|
|
|
local other_win = api.nvim_open_win(0, false, {
|
2023-07-24 06:19:01 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
})
|
|
|
|
feed('q:')
|
|
|
|
-- Cannot close the previous window.
|
|
|
|
eq(
|
|
|
|
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_hide, old_win)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-24 06:19:01 -07:00
|
|
|
-- Can close other windows.
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_hide(other_win)
|
|
|
|
eq(false, api.nvim_win_is_valid(other_win))
|
2023-07-26 17:38:23 -07:00
|
|
|
|
|
|
|
-- Closing curwin in context of a different window shouldn't close cmdwin.
|
|
|
|
other_win = api.nvim_open_win(old_buf, false, {
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
})
|
|
|
|
exec_lua(
|
|
|
|
[[
|
|
|
|
vim.api.nvim_win_call(..., function()
|
|
|
|
vim.api.nvim_win_hide(0)
|
|
|
|
end)
|
|
|
|
]],
|
|
|
|
other_win
|
|
|
|
)
|
|
|
|
eq(false, api.nvim_win_is_valid(other_win))
|
|
|
|
eq(':', fn.getcmdwintype())
|
|
|
|
-- Closing cmdwin in context of a non-previous window is still OK.
|
|
|
|
other_win = api.nvim_open_win(old_buf, false, {
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
})
|
|
|
|
exec_lua(
|
|
|
|
[[
|
|
|
|
local otherwin, cmdwin = ...
|
|
|
|
vim.api.nvim_win_call(otherwin, function()
|
|
|
|
vim.api.nvim_win_hide(cmdwin)
|
|
|
|
end)
|
|
|
|
]],
|
|
|
|
other_win,
|
|
|
|
api.nvim_get_current_win()
|
|
|
|
)
|
|
|
|
eq('', fn.getcmdwintype())
|
|
|
|
eq(true, api.nvim_win_is_valid(other_win))
|
2023-07-24 06:19:01 -07:00
|
|
|
end)
|
2021-03-09 20:21:45 -07:00
|
|
|
end)
|
2021-05-27 14:10:42 -07:00
|
|
|
|
2023-07-10 16:15:46 -07:00
|
|
|
describe('text_height', function()
|
|
|
|
it('validation', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local X = api.nvim_get_vvar('maxcol')
|
2023-07-10 16:15:46 -07:00
|
|
|
insert([[
|
|
|
|
aaa
|
|
|
|
bbb
|
|
|
|
ccc
|
|
|
|
ddd
|
|
|
|
eee]])
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('Invalid window id: 23', pcall_err(api.nvim_win_text_height, 23, {}))
|
|
|
|
eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { start_row = 5 }))
|
|
|
|
eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { start_row = -6 }))
|
|
|
|
eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { end_row = 5 }))
|
|
|
|
eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { end_row = -6 }))
|
2023-07-10 16:15:46 -07:00
|
|
|
eq(
|
|
|
|
"'start_row' is higher than 'end_row'",
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_text_height, 0, { start_row = 3, end_row = 1 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
eq(
|
|
|
|
"'start_vcol' specified without 'start_row'",
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_text_height, 0, { end_row = 2, start_vcol = 0 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
|
|
|
eq(
|
2023-07-10 16:15:46 -07:00
|
|
|
"'end_vcol' specified without 'end_row'",
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_text_height, 0, { start_row = 2, end_vcol = 0 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
eq(
|
|
|
|
"Invalid 'start_vcol': out of range",
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_text_height, 0, { start_row = 2, start_vcol = -1 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
eq(
|
|
|
|
"Invalid 'start_vcol': out of range",
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_text_height, 0, { start_row = 2, start_vcol = X + 1 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
eq(
|
|
|
|
"Invalid 'end_vcol': out of range",
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_text_height, 0, { end_row = 2, end_vcol = -1 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
eq(
|
|
|
|
"Invalid 'end_vcol': out of range",
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_text_height, 0, { end_row = 2, end_vcol = X + 1 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
eq(
|
|
|
|
"'start_vcol' is higher than 'end_vcol'",
|
|
|
|
pcall_err(
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height,
|
2024-01-12 06:11:28 -07:00
|
|
|
0,
|
2023-07-10 16:15:46 -07:00
|
|
|
{ start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 }
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with two diff windows', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local X = api.nvim_get_vvar('maxcol')
|
2023-07-10 16:15:46 -07:00
|
|
|
local screen = Screen.new(45, 22)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[0] = { foreground = Screen.colors.Blue1, bold = true },
|
|
|
|
[1] = { foreground = Screen.colors.Blue4, background = Screen.colors.Grey },
|
|
|
|
[2] = { foreground = Screen.colors.Brown },
|
|
|
|
[3] = {
|
|
|
|
foreground = Screen.colors.Blue1,
|
|
|
|
background = Screen.colors.LightCyan1,
|
|
|
|
bold = true,
|
2024-01-02 18:09:18 -07:00
|
|
|
},
|
2023-07-10 16:15:46 -07:00
|
|
|
[4] = { background = Screen.colors.LightBlue },
|
|
|
|
[5] = { foreground = Screen.colors.Blue4, background = Screen.colors.LightGrey },
|
|
|
|
[6] = { background = Screen.colors.Plum1 },
|
|
|
|
[7] = { background = Screen.colors.Red, bold = true },
|
|
|
|
[8] = { reverse = true },
|
|
|
|
[9] = { bold = true, reverse = true },
|
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
exec([[
|
|
|
|
set diffopt+=context:2 number
|
|
|
|
let expr = 'printf("%08d", v:val) .. repeat("!", v:val)'
|
|
|
|
call setline(1, map(range(1, 20) + range(25, 45), expr))
|
|
|
|
vnew
|
|
|
|
call setline(1, map(range(3, 20) + range(28, 50), expr))
|
|
|
|
windo diffthis
|
|
|
|
]])
|
|
|
|
feed('24gg')
|
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
{1: }{2: }{3:----------------}│{1: }{2: 1 }{4:00000001! }|
|
|
|
|
{1: }{2: }{3:----------------}│{1: }{2: 2 }{4:00000002!! }|
|
|
|
|
{1: }{2: 1 }00000003!!! │{1: }{2: 3 }00000003!!! |
|
|
|
|
{1: }{2: 2 }00000004!!!! │{1: }{2: 4 }00000004!!!! |
|
|
|
|
{1:+ }{2: 3 }{5:+-- 14 lines: 00}│{1:+ }{2: 5 }{5:+-- 14 lines: 00}|
|
|
|
|
{1: }{2: 17 }00000019!!!!!!!!│{1: }{2: 19 }00000019!!!!!!!!|
|
|
|
|
{1: }{2: 18 }00000020!!!!!!!!│{1: }{2: 20 }00000020!!!!!!!!|
|
|
|
|
{1: }{2: }{3:----------------}│{1: }{2: 21 }{4:00000025!!!!!!!!}|
|
|
|
|
{1: }{2: }{3:----------------}│{1: }{2: 22 }{4:00000026!!!!!!!!}|
|
|
|
|
{1: }{2: }{3:----------------}│{1: }{2: 23 }{4:00000027!!!!!!!!}|
|
|
|
|
{1: }{2: 19 }00000028!!!!!!!!│{1: }{2: 24 }^00000028!!!!!!!!|
|
|
|
|
{1: }{2: 20 }00000029!!!!!!!!│{1: }{2: 25 }00000029!!!!!!!!|
|
|
|
|
{1:+ }{2: 21 }{5:+-- 14 lines: 00}│{1:+ }{2: 26 }{5:+-- 14 lines: 00}|
|
|
|
|
{1: }{2: 35 }00000044!!!!!!!!│{1: }{2: 40 }00000044!!!!!!!!|
|
|
|
|
{1: }{2: 36 }00000045!!!!!!!!│{1: }{2: 41 }00000045!!!!!!!!|
|
|
|
|
{1: }{2: 37 }{4:00000046!!!!!!!!}│{1: }{2: }{3:----------------}|
|
|
|
|
{1: }{2: 38 }{4:00000047!!!!!!!!}│{1: }{2: }{3:----------------}|
|
|
|
|
{1: }{2: 39 }{4:00000048!!!!!!!!}│{1: }{2: }{3:----------------}|
|
|
|
|
{1: }{2: 40 }{4:00000049!!!!!!!!}│{1: }{2: }{3:----------------}|
|
|
|
|
{1: }{2: 41 }{4:00000050!!!!!!!!}│{1: }{2: }{3:----------------}|
|
|
|
|
{8:[No Name] [+] }{9:[No Name] [+] }|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
|
|
|
screen:try_resize(45, 3)
|
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
{1: }{2: 19 }00000028!!!!!!!!│{1: }{2: 24 }^00000028!!!!!!!!|
|
|
|
|
{8:[No Name] [+] }{9:[No Name] [+] }|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1000, {}))
|
|
|
|
eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, {}))
|
|
|
|
eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1000, { start_row = 0 }))
|
|
|
|
eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { start_row = 0 }))
|
|
|
|
eq({ all = 15, fill = 0 }, api.nvim_win_text_height(1000, { end_row = -1 }))
|
|
|
|
eq({ all = 15, fill = 0 }, api.nvim_win_text_height(1000, { end_row = 40 }))
|
|
|
|
eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { end_row = -1 }))
|
|
|
|
eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 40 }))
|
|
|
|
eq({ all = 10, fill = 5 }, api.nvim_win_text_height(1000, { start_row = 23 }))
|
|
|
|
eq({ all = 13, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 18 }))
|
|
|
|
eq({ all = 11, fill = 0 }, api.nvim_win_text_height(1000, { end_row = 23 }))
|
|
|
|
eq({ all = 11, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18 }))
|
|
|
|
eq({ all = 11, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 3, end_row = 39 }))
|
|
|
|
eq({ all = 11, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 1, end_row = 34 }))
|
|
|
|
eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 4, end_row = 38 }))
|
|
|
|
eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 2, end_row = 33 }))
|
|
|
|
eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 5, end_row = 37 }))
|
|
|
|
eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 3, end_row = 32 }))
|
|
|
|
eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 17, end_row = 25 }))
|
|
|
|
eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 15, end_row = 20 }))
|
|
|
|
eq({ all = 7, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 18, end_row = 24 }))
|
|
|
|
eq({ all = 7, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 16, end_row = 19 }))
|
|
|
|
eq({ all = 6, fill = 5 }, api.nvim_win_text_height(1000, { start_row = -1 }))
|
|
|
|
eq({ all = 5, fill = 5 }, api.nvim_win_text_height(1000, { start_row = -1, start_vcol = X }))
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 0, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 0, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(
|
2024-01-12 05:44:54 -07:00
|
|
|
1000,
|
|
|
|
{ start_row = -1, start_vcol = X, end_row = -1, end_vcol = X }
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 1, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(
|
2024-01-12 05:44:54 -07:00
|
|
|
1000,
|
|
|
|
{ start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X }
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ all = 3, fill = 2 }, api.nvim_win_text_height(1001, { end_row = 0 }))
|
|
|
|
eq({ all = 2, fill = 2 }, api.nvim_win_text_height(1001, { end_row = 0, end_vcol = 0 }))
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 2, fill = 2 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 0, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 1, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ all = 11, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18 }))
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 9, fill = 3 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ all = 10, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18, end_vcol = 0 }))
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 8, fill = 3 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(
|
2024-01-12 05:44:54 -07:00
|
|
|
1001,
|
|
|
|
{ start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 }
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('with wrapped lines', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local X = api.nvim_get_vvar('maxcol')
|
2023-07-10 16:15:46 -07:00
|
|
|
local screen = Screen.new(45, 22)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[0] = { foreground = Screen.colors.Blue1, bold = true },
|
|
|
|
[1] = { foreground = Screen.colors.Brown },
|
|
|
|
[2] = { background = Screen.colors.Yellow },
|
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
exec([[
|
|
|
|
set number cpoptions+=n
|
|
|
|
call setline(1, repeat([repeat('foobar-', 36)], 3))
|
|
|
|
]])
|
2024-01-12 10:59:57 -07:00
|
|
|
local ns = api.nvim_create_namespace('')
|
|
|
|
api.nvim_buf_set_extmark(
|
2023-07-10 16:15:46 -07:00
|
|
|
0,
|
|
|
|
ns,
|
|
|
|
1,
|
|
|
|
100,
|
|
|
|
{ virt_text = { { ('?'):rep(15), 'Search' } }, virt_text_pos = 'inline' }
|
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_buf_set_extmark(
|
2023-07-10 16:15:46 -07:00
|
|
|
0,
|
|
|
|
ns,
|
|
|
|
2,
|
|
|
|
200,
|
|
|
|
{ virt_text = { { ('!'):rep(75), 'Search' } }, virt_text_pos = 'inline' }
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
{1: 1 }^foobar-foobar-foobar-foobar-foobar-foobar|
|
|
|
|
-foobar-foobar-foobar-foobar-foobar-foobar-fo|
|
|
|
|
obar-foobar-foobar-foobar-foobar-foobar-fooba|
|
|
|
|
r-foobar-foobar-foobar-foobar-foobar-foobar-f|
|
|
|
|
oobar-foobar-foobar-foobar-foobar-foobar-foob|
|
|
|
|
ar-foobar-foobar-foobar-foobar- |
|
|
|
|
{1: 2 }foobar-foobar-foobar-foobar-foobar-foobar|
|
|
|
|
-foobar-foobar-foobar-foobar-foobar-foobar-fo|
|
|
|
|
obar-foobar-fo{2:???????????????}obar-foobar-foob|
|
|
|
|
ar-foobar-foobar-foobar-foobar-foobar-foobar-|
|
|
|
|
foobar-foobar-foobar-foobar-foobar-foobar-foo|
|
|
|
|
bar-foobar-foobar-foobar-foobar-foobar-foobar|
|
|
|
|
- |
|
|
|
|
{1: 3 }foobar-foobar-foobar-foobar-foobar-foobar|
|
|
|
|
-foobar-foobar-foobar-foobar-foobar-foobar-fo|
|
|
|
|
obar-foobar-foobar-foobar-foobar-foobar-fooba|
|
|
|
|
r-foobar-foobar-foobar-foobar-foobar-foobar-f|
|
|
|
|
oobar-foobar-foobar-foob{2:!!!!!!!!!!!!!!!!!!!!!}|
|
|
|
|
{2:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}|
|
|
|
|
{2:!!!!!!!!!}ar-foobar-foobar-foobar-foobar-fooba|
|
|
|
|
r-foobar-foobar- |
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
|
|
|
screen:try_resize(45, 2)
|
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
|
|
|
{1: 1 }^foobar-foobar-foobar-foobar-foobar-foobar|
|
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ all = 21, fill = 0 }, api.nvim_win_text_height(0, {}))
|
|
|
|
eq({ all = 6, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, end_row = 0 }))
|
|
|
|
eq({ all = 7, fill = 0 }, api.nvim_win_text_height(0, { start_row = 1, end_row = 1 }))
|
|
|
|
eq({ all = 8, fill = 0 }, api.nvim_win_text_height(0, { start_row = 2, end_row = 2 }))
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 0, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 0 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 1, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 2, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 2, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 3, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 6, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 7, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 7, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 7, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 7, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 7, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 6, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 6, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 5, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 2, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 1, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 1, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 0, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 1, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = 131 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 1, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(
|
2024-01-12 05:44:54 -07:00
|
|
|
0,
|
|
|
|
{ start_row = 1, start_vcol = 221, end_row = 1, end_vcol = 266 }
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ all = 18, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 131 }))
|
|
|
|
eq({ all = 19, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 130 }))
|
|
|
|
eq({ all = 20, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 311 }))
|
|
|
|
eq({ all = 21, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 312 }))
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 17, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(
|
2024-01-12 05:44:54 -07:00
|
|
|
0,
|
|
|
|
{ start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 }
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 19, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(
|
2024-01-12 05:44:54 -07:00
|
|
|
0,
|
|
|
|
{ start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 }
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ all = 16, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 221 }))
|
|
|
|
eq({ all = 17, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 220 }))
|
|
|
|
eq({ all = 14, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 41 }))
|
|
|
|
eq({ all = 15, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 42 }))
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 9, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-16 03:02:53 -07:00
|
|
|
eq(
|
|
|
|
{ all = 11, fill = 0 },
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-10 16:15:46 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2021-05-27 14:10:42 -07:00
|
|
|
describe('open_win', function()
|
|
|
|
it('noautocmd option works', function()
|
|
|
|
command('autocmd BufEnter,BufLeave,BufWinEnter * let g:fired = 1')
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_open_win(api.nvim_create_buf(true, true), true, {
|
2021-05-27 14:10:42 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
noautocmd = true,
|
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(0, fn.exists('g:fired'))
|
|
|
|
api.nvim_open_win(api.nvim_create_buf(true, true), true, {
|
2021-05-27 14:10:42 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
})
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(1, fn.exists('g:fired'))
|
2021-05-27 14:10:42 -07:00
|
|
|
end)
|
2023-07-23 11:50:20 -07:00
|
|
|
|
2023-07-26 17:38:23 -07:00
|
|
|
it('disallowed in cmdwin if enter=true or buf=cmdwin_buf', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local new_buf = api.nvim_create_buf(true, true)
|
2023-07-23 11:50:20 -07:00
|
|
|
feed('q:')
|
|
|
|
eq(
|
|
|
|
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_open_win, new_buf, true, {
|
2023-07-23 11:50:20 -07:00
|
|
|
relative = 'editor',
|
|
|
|
row = 5,
|
|
|
|
col = 5,
|
|
|
|
width = 5,
|
|
|
|
height = 5,
|
|
|
|
})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-23 11:50:20 -07:00
|
|
|
eq(
|
|
|
|
'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_open_win, 0, false, {
|
2023-07-23 11:50:20 -07:00
|
|
|
relative = 'editor',
|
|
|
|
row = 5,
|
|
|
|
col = 5,
|
|
|
|
width = 5,
|
|
|
|
height = 5,
|
|
|
|
})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-26 17:38:23 -07:00
|
|
|
matches(
|
|
|
|
'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$',
|
|
|
|
pcall_err(
|
|
|
|
exec_lua,
|
|
|
|
[[
|
|
|
|
local cmdwin_buf = vim.api.nvim_get_current_buf()
|
|
|
|
vim.api.nvim_buf_call(vim.api.nvim_create_buf(false, true), function()
|
|
|
|
vim.api.nvim_open_win(cmdwin_buf, false, {
|
|
|
|
relative='editor', row=5, col=5, width=5, height=5,
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
]]
|
|
|
|
)
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
|
2023-07-23 11:50:20 -07:00
|
|
|
eq(
|
|
|
|
new_buf,
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_win_get_buf(api.nvim_open_win(new_buf, false, {
|
2023-07-23 11:50:20 -07:00
|
|
|
relative = 'editor',
|
|
|
|
row = 5,
|
|
|
|
col = 5,
|
|
|
|
width = 5,
|
|
|
|
height = 5,
|
|
|
|
}))
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-07-23 11:50:20 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('aborts if buffer is invalid', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local wins_before = api.nvim_list_wins()
|
2023-07-23 11:50:20 -07:00
|
|
|
eq(
|
|
|
|
'Invalid buffer id: 1337',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_open_win, 1337, false, {
|
2023-07-23 11:50:20 -07:00
|
|
|
relative = 'editor',
|
|
|
|
row = 5,
|
|
|
|
col = 5,
|
|
|
|
width = 5,
|
|
|
|
height = 5,
|
|
|
|
})
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(wins_before, api.nvim_list_wins())
|
2023-07-23 11:50:20 -07:00
|
|
|
end)
|
2024-01-31 20:43:35 -07:00
|
|
|
|
|
|
|
it('creates a split window', function()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
eq('', api.nvim_win_get_config(win).relative)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('creates split windows in the correct direction', function()
|
|
|
|
local initial_win = api.nvim_get_current_win()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = true,
|
|
|
|
})
|
|
|
|
eq('', api.nvim_win_get_config(win).relative)
|
|
|
|
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
|
|
|
|
eq({
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', win },
|
|
|
|
{ 'leaf', initial_win },
|
|
|
|
},
|
|
|
|
}, layout)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("respects the 'split' option", function()
|
|
|
|
local initial_win = api.nvim_get_current_win()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
split = 'below',
|
|
|
|
})
|
|
|
|
eq('', api.nvim_win_get_config(win).relative)
|
|
|
|
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
|
|
|
|
eq({
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', initial_win },
|
|
|
|
{ 'leaf', win },
|
|
|
|
},
|
|
|
|
}, layout)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it(
|
|
|
|
"doesn't change tp_curwin when splitting window in non-current tab with enter=false",
|
|
|
|
function()
|
|
|
|
local tab1 = api.nvim_get_current_tabpage()
|
|
|
|
local tab1_win = api.nvim_get_current_win()
|
|
|
|
|
|
|
|
helpers.command('tabnew')
|
|
|
|
local tab2 = api.nvim_get_current_tabpage()
|
|
|
|
local tab2_win = api.nvim_get_current_win()
|
|
|
|
|
|
|
|
eq({ tab1_win, tab2_win }, api.nvim_list_wins())
|
|
|
|
eq({ tab1, tab2 }, api.nvim_list_tabpages())
|
|
|
|
|
|
|
|
api.nvim_set_current_tabpage(tab1)
|
|
|
|
eq(tab1_win, api.nvim_get_current_win())
|
|
|
|
|
|
|
|
local tab2_prevwin = fn.tabpagewinnr(tab2, '#')
|
|
|
|
|
|
|
|
-- split in tab2 whine in tab2, with enter = false
|
|
|
|
local tab2_win2 = api.nvim_open_win(api.nvim_create_buf(false, true), false, {
|
|
|
|
win = tab2_win,
|
|
|
|
split = 'right',
|
|
|
|
})
|
|
|
|
eq(tab1_win, api.nvim_get_current_win()) -- we should still be in the first tp
|
|
|
|
eq(tab1_win, api.nvim_tabpage_get_win(tab1))
|
|
|
|
|
|
|
|
eq(tab2_win, api.nvim_tabpage_get_win(tab2)) -- tab2's tp_curwin should not have changed
|
|
|
|
eq(tab2_prevwin, fn.tabpagewinnr(tab2, '#')) -- tab2's tp_prevwin should not have changed
|
|
|
|
eq({ tab1_win, tab2_win, tab2_win2 }, api.nvim_list_wins())
|
|
|
|
eq({ tab2_win, tab2_win2 }, api.nvim_tabpage_list_wins(tab2))
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
it('creates splits in the correct location', function()
|
|
|
|
local first_win = api.nvim_get_current_win()
|
|
|
|
-- specifying window 0 should create a split next to the current window
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
eq({
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win },
|
|
|
|
{ 'leaf', first_win },
|
|
|
|
},
|
|
|
|
}, layout)
|
|
|
|
-- not specifying a window should create a top-level split
|
|
|
|
local win2 = api.nvim_open_win(0, true, {
|
|
|
|
split = 'left',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
layout = fn.winlayout()
|
|
|
|
eq({
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', win2 },
|
|
|
|
{
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win },
|
|
|
|
{ 'leaf', first_win },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, layout)
|
|
|
|
|
|
|
|
-- specifying a window should create a split next to that window
|
|
|
|
local win3 = api.nvim_open_win(0, true, {
|
|
|
|
win = win,
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
layout = fn.winlayout()
|
|
|
|
eq({
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', win2 },
|
|
|
|
{
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win3 },
|
|
|
|
{ 'leaf', win },
|
|
|
|
{ 'leaf', first_win },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, layout)
|
|
|
|
end)
|
fix(api): open_win fire BufWinEnter for other buffer when !enter && !noautocmd
Problem: BufWinEnter is not fired when not entering a new window, even when a
different buffer is specified and buffer-related autocommands are unblocked
(!noautocmd).
Solution: fire it in the context of the new window and buffer. Do not do it if
the buffer is unchanged, like :{s}buffer.
Be wary of autocommands! For example, it's possible for nvim_win_set_config to
be used in an autocommand to move a window to a different tabpage (in contrast,
things like wincmd T actually create a *new* window, so it may not have been
possible before, meaning other parts of Nvim could assume windows can't do
this... I'd be especially cautious of logic that restores curwin and curtab
without checking if curwin is still valid in curtab, if any such logic exists).
Also, bail early from win_set_buf if setting the temp curwin fails; this
shouldn't be possible, as the callers check that wp is valid, but in case that's
not true, win_set_buf will no longer continue setting a buffer for the wrong
window.
Note that pum_create_float_preview also uses win_set_buf, but from a glance,
doesn't look like it properly checks for autocmds screwing things up (win_enter,
nvim_create_buf...). I haven't addressed that here.
Also adds some test coverage for nvim_open_win autocommands.
Closes #27121.
2024-02-03 19:59:26 -07:00
|
|
|
|
|
|
|
local function setup_tabbed_autocmd_test()
|
|
|
|
local info = {}
|
|
|
|
info.orig_buf = api.nvim_get_current_buf()
|
|
|
|
info.other_buf = api.nvim_create_buf(true, true)
|
|
|
|
info.tab1_curwin = api.nvim_get_current_win()
|
|
|
|
info.tab1 = api.nvim_get_current_tabpage()
|
|
|
|
command('tab split | split')
|
|
|
|
info.tab2_curwin = api.nvim_get_current_win()
|
|
|
|
info.tab2 = api.nvim_get_current_tabpage()
|
|
|
|
exec([=[
|
|
|
|
tabfirst
|
|
|
|
let result = []
|
|
|
|
autocmd TabEnter * let result += [["TabEnter", nvim_get_current_tabpage()]]
|
|
|
|
autocmd TabLeave * let result += [["TabLeave", nvim_get_current_tabpage()]]
|
|
|
|
autocmd WinEnter * let result += [["WinEnter", win_getid()]]
|
|
|
|
autocmd WinLeave * let result += [["WinLeave", win_getid()]]
|
|
|
|
autocmd WinNew * let result += [["WinNew", win_getid()]]
|
|
|
|
autocmd WinClosed * let result += [["WinClosed", str2nr(expand("<afile>"))]]
|
|
|
|
autocmd BufEnter * let result += [["BufEnter", win_getid(), bufnr()]]
|
|
|
|
autocmd BufLeave * let result += [["BufLeave", win_getid(), bufnr()]]
|
|
|
|
autocmd BufWinEnter * let result += [["BufWinEnter", win_getid(), bufnr()]]
|
|
|
|
autocmd BufWinLeave * let result += [["BufWinLeave", win_getid(), bufnr()]]
|
|
|
|
]=])
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
|
|
|
it('fires expected autocmds when creating splits without entering', function()
|
|
|
|
local info = setup_tabbed_autocmd_test()
|
|
|
|
|
|
|
|
-- For these, don't want BufWinEnter if visiting the same buffer, like :{s}buffer.
|
|
|
|
-- Same tabpage, same buffer.
|
|
|
|
local new_win = api.nvim_open_win(0, false, { split = 'left', win = info.tab1_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
}, eval('result'))
|
|
|
|
eq(info.tab1_curwin, api.nvim_get_current_win())
|
|
|
|
|
|
|
|
-- Other tabpage, same buffer.
|
|
|
|
command('let result = []')
|
|
|
|
new_win = api.nvim_open_win(0, false, { split = 'left', win = info.tab2_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
}, eval('result'))
|
|
|
|
eq(info.tab1_curwin, api.nvim_get_current_win())
|
|
|
|
|
|
|
|
-- Same tabpage, other buffer.
|
|
|
|
command('let result = []')
|
|
|
|
new_win = api.nvim_open_win(info.other_buf, false, { split = 'left', win = info.tab1_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
{ 'BufWinEnter', new_win, info.other_buf },
|
|
|
|
}, eval('result'))
|
|
|
|
eq(info.tab1_curwin, api.nvim_get_current_win())
|
|
|
|
|
|
|
|
-- Other tabpage, other buffer.
|
|
|
|
command('let result = []')
|
|
|
|
new_win = api.nvim_open_win(info.other_buf, false, { split = 'left', win = info.tab2_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
{ 'BufWinEnter', new_win, info.other_buf },
|
|
|
|
}, eval('result'))
|
|
|
|
eq(info.tab1_curwin, api.nvim_get_current_win())
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('fires expected autocmds when creating and entering splits', function()
|
|
|
|
local info = setup_tabbed_autocmd_test()
|
|
|
|
|
|
|
|
-- Same tabpage, same buffer.
|
|
|
|
local new_win = api.nvim_open_win(0, true, { split = 'left', win = info.tab1_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
{ 'WinLeave', info.tab1_curwin },
|
|
|
|
{ 'WinEnter', new_win },
|
|
|
|
}, eval('result'))
|
|
|
|
|
|
|
|
-- Same tabpage, other buffer.
|
|
|
|
api.nvim_set_current_win(info.tab1_curwin)
|
|
|
|
command('let result = []')
|
|
|
|
new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab1_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
{ 'WinLeave', info.tab1_curwin },
|
|
|
|
{ 'WinEnter', new_win },
|
|
|
|
{ 'BufLeave', new_win, info.orig_buf },
|
|
|
|
{ 'BufEnter', new_win, info.other_buf },
|
|
|
|
{ 'BufWinEnter', new_win, info.other_buf },
|
|
|
|
}, eval('result'))
|
|
|
|
|
|
|
|
-- For these, the other tabpage's prevwin and curwin will change like we switched from its old
|
|
|
|
-- curwin to the new window, so the extra events near TabEnter reflect that.
|
|
|
|
-- Other tabpage, same buffer.
|
|
|
|
api.nvim_set_current_win(info.tab1_curwin)
|
|
|
|
command('let result = []')
|
|
|
|
new_win = api.nvim_open_win(0, true, { split = 'left', win = info.tab2_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
{ 'WinLeave', info.tab1_curwin },
|
|
|
|
{ 'TabLeave', info.tab1 },
|
|
|
|
|
|
|
|
{ 'WinEnter', info.tab2_curwin },
|
|
|
|
{ 'TabEnter', info.tab2 },
|
|
|
|
{ 'WinLeave', info.tab2_curwin },
|
|
|
|
{ 'WinEnter', new_win },
|
|
|
|
}, eval('result'))
|
|
|
|
|
|
|
|
-- Other tabpage, other buffer.
|
|
|
|
api.nvim_set_current_win(info.tab2_curwin)
|
|
|
|
api.nvim_set_current_win(info.tab1_curwin)
|
|
|
|
command('let result = []')
|
|
|
|
new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab2_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
{ 'WinLeave', info.tab1_curwin },
|
|
|
|
{ 'TabLeave', info.tab1 },
|
|
|
|
|
|
|
|
{ 'WinEnter', info.tab2_curwin },
|
|
|
|
{ 'TabEnter', info.tab2 },
|
|
|
|
{ 'WinLeave', info.tab2_curwin },
|
|
|
|
{ 'WinEnter', new_win },
|
|
|
|
|
|
|
|
{ 'BufLeave', new_win, info.orig_buf },
|
|
|
|
{ 'BufEnter', new_win, info.other_buf },
|
|
|
|
{ 'BufWinEnter', new_win, info.other_buf },
|
|
|
|
}, eval('result'))
|
|
|
|
|
|
|
|
-- Other tabpage, other buffer; but other tabpage's curwin has a new buffer active.
|
|
|
|
api.nvim_set_current_win(info.tab2_curwin)
|
|
|
|
local new_buf = api.nvim_create_buf(true, true)
|
|
|
|
api.nvim_set_current_buf(new_buf)
|
|
|
|
api.nvim_set_current_win(info.tab1_curwin)
|
|
|
|
command('let result = []')
|
|
|
|
new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab2_curwin })
|
|
|
|
eq({
|
|
|
|
{ 'WinNew', new_win },
|
|
|
|
{ 'BufLeave', info.tab1_curwin, info.orig_buf },
|
|
|
|
{ 'WinLeave', info.tab1_curwin },
|
|
|
|
{ 'TabLeave', info.tab1 },
|
|
|
|
|
|
|
|
{ 'WinEnter', info.tab2_curwin },
|
|
|
|
{ 'TabEnter', info.tab2 },
|
|
|
|
{ 'BufEnter', info.tab2_curwin, new_buf },
|
|
|
|
{ 'WinLeave', info.tab2_curwin },
|
|
|
|
{ 'WinEnter', new_win },
|
|
|
|
{ 'BufLeave', new_win, new_buf },
|
|
|
|
{ 'BufEnter', new_win, info.other_buf },
|
|
|
|
{ 'BufWinEnter', new_win, info.other_buf },
|
|
|
|
}, eval('result'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('OK when new window is moved to other tabpage by autocommands', function()
|
|
|
|
-- Use nvim_win_set_config in the autocommands, as other methods of moving a window to a
|
|
|
|
-- different tabpage (e.g: wincmd T) actually creates a new window.
|
|
|
|
local tab0 = api.nvim_get_current_tabpage()
|
|
|
|
local tab0_win = api.nvim_get_current_win()
|
|
|
|
command('tabnew')
|
|
|
|
local new_buf = api.nvim_create_buf(true, true)
|
|
|
|
local tab1 = api.nvim_get_current_tabpage()
|
|
|
|
local tab1_parent = api.nvim_get_current_win()
|
|
|
|
command(
|
|
|
|
'tabfirst | autocmd WinNew * ++once call nvim_win_set_config(0, #{split: "left", win: '
|
|
|
|
.. tab1_parent
|
|
|
|
.. '})'
|
|
|
|
)
|
|
|
|
local new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
|
|
|
|
eq(tab1, api.nvim_get_current_tabpage())
|
|
|
|
eq(new_win, api.nvim_get_current_win())
|
|
|
|
eq(new_buf, api.nvim_get_current_buf())
|
|
|
|
|
|
|
|
-- nvim_win_set_config called after entering. It doesn't follow a curwin that is moved to a
|
|
|
|
-- different tabpage, but instead moves to the win filling the space, which is tab0_win.
|
|
|
|
command(
|
|
|
|
'tabfirst | autocmd WinEnter * ++once call nvim_win_set_config(0, #{split: "left", win: '
|
|
|
|
.. tab1_parent
|
|
|
|
.. '})'
|
|
|
|
)
|
|
|
|
new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
|
|
|
|
eq(tab0, api.nvim_get_current_tabpage())
|
|
|
|
eq(tab0_win, api.nvim_get_current_win())
|
|
|
|
eq(tab1, api.nvim_win_get_tabpage(new_win))
|
|
|
|
eq(new_buf, api.nvim_win_get_buf(new_win))
|
|
|
|
|
|
|
|
command(
|
|
|
|
'tabfirst | autocmd BufEnter * ++once call nvim_win_set_config(0, #{split: "left", win: '
|
|
|
|
.. tab1_parent
|
|
|
|
.. '})'
|
|
|
|
)
|
|
|
|
new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
|
|
|
|
eq(tab0, api.nvim_get_current_tabpage())
|
|
|
|
eq(tab0_win, api.nvim_get_current_win())
|
|
|
|
eq(tab1, api.nvim_win_get_tabpage(new_win))
|
|
|
|
eq(new_buf, api.nvim_win_get_buf(new_win))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not fire BufWinEnter if win_set_buf fails', function()
|
|
|
|
exec([[
|
|
|
|
set nohidden modified
|
|
|
|
autocmd WinNew * ++once only!
|
|
|
|
let fired = v:false
|
|
|
|
autocmd BufWinEnter * ++once let fired = v:true
|
|
|
|
]])
|
|
|
|
eq(
|
|
|
|
'Failed to set buffer 2',
|
|
|
|
pcall_err(api.nvim_open_win, api.nvim_create_buf(true, true), false, { split = 'left' })
|
|
|
|
)
|
|
|
|
eq(false, eval('fired'))
|
|
|
|
end)
|
2024-02-11 11:45:56 -07:00
|
|
|
|
|
|
|
it('fires Buf* autocommands when `!enter` if window is entered via autocommands', function()
|
|
|
|
exec([[
|
|
|
|
autocmd WinNew * ++once only!
|
|
|
|
let fired = v:false
|
|
|
|
autocmd BufEnter * ++once let fired = v:true
|
|
|
|
]])
|
|
|
|
api.nvim_open_win(api.nvim_create_buf(true, true), false, { split = 'left' })
|
|
|
|
eq(true, eval('fired'))
|
|
|
|
end)
|
2024-02-11 13:15:47 -07:00
|
|
|
|
|
|
|
it('no heap-use-after-free if target buffer deleted by autocommands', function()
|
|
|
|
local cur_buf = api.nvim_get_current_buf()
|
|
|
|
local new_buf = api.nvim_create_buf(true, true)
|
|
|
|
command('autocmd WinNew * ++once call nvim_buf_delete(' .. new_buf .. ', #{force: 1})')
|
|
|
|
api.nvim_open_win(new_buf, true, { split = 'left' })
|
|
|
|
eq(cur_buf, api.nvim_get_current_buf())
|
|
|
|
end)
|
2024-02-07 10:17:44 -07:00
|
|
|
|
|
|
|
it('checks if splitting disallowed', function()
|
|
|
|
command('split | autocmd WinEnter * ++once call nvim_open_win(0, 0, #{split: "right"})')
|
|
|
|
matches("E242: Can't split a window while closing another$", pcall_err(command, 'quit'))
|
|
|
|
|
|
|
|
command('only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left"})')
|
|
|
|
matches(
|
|
|
|
'E1159: Cannot split a window when closing the buffer$',
|
|
|
|
pcall_err(command, 'new | quit')
|
|
|
|
)
|
|
|
|
|
|
|
|
local w = api.nvim_get_current_win()
|
|
|
|
command(
|
|
|
|
'only | new | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left", win: '
|
|
|
|
.. w
|
|
|
|
.. '})'
|
|
|
|
)
|
|
|
|
matches(
|
|
|
|
'E1159: Cannot split a window when closing the buffer$',
|
|
|
|
pcall_err(api.nvim_win_close, w, true)
|
|
|
|
)
|
|
|
|
|
|
|
|
-- OK when using window to different buffer than `win`s.
|
|
|
|
w = api.nvim_get_current_win()
|
|
|
|
command(
|
|
|
|
'only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left", win: '
|
|
|
|
.. w
|
|
|
|
.. '})'
|
|
|
|
)
|
|
|
|
command('new | quit')
|
|
|
|
end)
|
2024-02-11 15:53:37 -07:00
|
|
|
|
|
|
|
it('restores last known cursor position if BufWinEnter did not move it', function()
|
|
|
|
-- This test mostly exists to ensure BufWinEnter is executed before enter_buffer's epilogue.
|
|
|
|
local buf = api.nvim_get_current_buf()
|
|
|
|
insert([[
|
|
|
|
foo
|
|
|
|
bar baz .etc
|
|
|
|
i love autocommand bugs!
|
|
|
|
supercalifragilisticexpialidocious
|
|
|
|
marvim is actually a human
|
|
|
|
llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch
|
|
|
|
]])
|
|
|
|
api.nvim_win_set_cursor(0, { 5, 2 })
|
|
|
|
command('set nostartofline | enew')
|
|
|
|
local new_win = api.nvim_open_win(buf, false, { split = 'left' })
|
|
|
|
eq({ 5, 2 }, api.nvim_win_get_cursor(new_win))
|
|
|
|
|
|
|
|
exec([[
|
|
|
|
only!
|
|
|
|
autocmd BufWinEnter * ++once normal! j6l
|
|
|
|
]])
|
|
|
|
new_win = api.nvim_open_win(buf, false, { split = 'left' })
|
|
|
|
eq({ 2, 6 }, api.nvim_win_get_cursor(new_win))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('does not block all win_set_buf autocommands if !enter and !noautocmd', function()
|
|
|
|
local new_buf = fn.bufadd('foobarbaz')
|
|
|
|
exec([[
|
|
|
|
let triggered = ""
|
|
|
|
autocmd BufReadCmd * ++once let triggered = bufname()
|
|
|
|
]])
|
|
|
|
api.nvim_open_win(new_buf, false, { split = 'left' })
|
|
|
|
eq('foobarbaz', eval('triggered'))
|
|
|
|
end)
|
2024-01-31 20:43:35 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('set_config', function()
|
|
|
|
it('moves a split into a float', function()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
eq('', api.nvim_win_get_config(win).relative)
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
relative = 'editor',
|
|
|
|
row = 5,
|
|
|
|
col = 5,
|
|
|
|
width = 5,
|
|
|
|
height = 5,
|
|
|
|
})
|
|
|
|
eq('editor', api.nvim_win_get_config(win).relative)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('throws error when attempting to move the last window', function()
|
|
|
|
local err = pcall_err(api.nvim_win_set_config, 0, {
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
eq('Cannot move last window', err)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('passing retval of get_config results in no-op', function()
|
|
|
|
-- simple split layout
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
split = 'left',
|
|
|
|
})
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
local config = api.nvim_win_get_config(win)
|
|
|
|
api.nvim_win_set_config(win, config)
|
|
|
|
eq(layout, fn.winlayout())
|
|
|
|
|
|
|
|
-- nested split layout
|
|
|
|
local win2 = api.nvim_open_win(0, true, {
|
|
|
|
vertical = true,
|
|
|
|
})
|
|
|
|
local win3 = api.nvim_open_win(0, true, {
|
|
|
|
win = win2,
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
layout = fn.winlayout()
|
|
|
|
config = api.nvim_win_get_config(win2)
|
|
|
|
api.nvim_win_set_config(win2, config)
|
|
|
|
eq(layout, fn.winlayout())
|
|
|
|
|
|
|
|
config = api.nvim_win_get_config(win3)
|
|
|
|
api.nvim_win_set_config(win3, config)
|
|
|
|
eq(layout, fn.winlayout())
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('moves a float into a split', function()
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
eq('leaf', layout[1])
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
relative = 'editor',
|
|
|
|
row = 5,
|
|
|
|
col = 5,
|
|
|
|
width = 5,
|
|
|
|
height = 5,
|
|
|
|
})
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'below',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
eq('', api.nvim_win_get_config(win).relative)
|
|
|
|
layout = fn.winlayout()
|
|
|
|
eq('col', layout[1])
|
|
|
|
eq(2, #layout[2])
|
|
|
|
eq(win, layout[2][2][2])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('respects the "split" option', function()
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
eq('leaf', layout[1])
|
|
|
|
local first_win = layout[2]
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
relative = 'editor',
|
|
|
|
row = 5,
|
|
|
|
col = 5,
|
|
|
|
width = 5,
|
|
|
|
height = 5,
|
|
|
|
})
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'right',
|
|
|
|
win = first_win,
|
|
|
|
})
|
|
|
|
layout = fn.winlayout()
|
|
|
|
eq('row', layout[1])
|
|
|
|
eq(2, #layout[2])
|
|
|
|
eq(win, layout[2][2][2])
|
|
|
|
local config = api.nvim_win_get_config(win)
|
|
|
|
eq('', config.relative)
|
|
|
|
eq('right', config.split)
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'below',
|
|
|
|
win = first_win,
|
|
|
|
})
|
|
|
|
layout = fn.winlayout()
|
|
|
|
eq('col', layout[1])
|
|
|
|
eq(2, #layout[2])
|
|
|
|
eq(win, layout[2][2][2])
|
|
|
|
config = api.nvim_win_get_config(win)
|
|
|
|
eq('', config.relative)
|
|
|
|
eq('below', config.split)
|
2024-02-07 14:44:42 -07:00
|
|
|
|
|
|
|
eq(
|
|
|
|
"non-float with 'win' requires at least 'split' or 'vertical'",
|
|
|
|
pcall_err(api.nvim_win_set_config, 0, { win = 0 })
|
|
|
|
)
|
|
|
|
eq(
|
|
|
|
"non-float with 'win' requires at least 'split' or 'vertical'",
|
|
|
|
pcall_err(api.nvim_win_set_config, 0, { win = 0, relative = '' })
|
|
|
|
)
|
2024-01-31 20:43:35 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('creates top-level splits', function()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
local win2 = api.nvim_open_win(0, true, {
|
|
|
|
vertical = true,
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
eq('row', layout[1])
|
|
|
|
eq(2, #layout[2])
|
|
|
|
eq(win2, layout[2][1][2])
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'below',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
layout = fn.winlayout()
|
|
|
|
eq('col', layout[1])
|
|
|
|
eq(2, #layout[2])
|
|
|
|
eq('row', layout[2][1][1])
|
|
|
|
eq(win, layout[2][2][2])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('moves splits to other tabpages', function()
|
|
|
|
local curtab = api.nvim_get_current_tabpage()
|
|
|
|
local win = api.nvim_open_win(0, false, { split = 'left' })
|
|
|
|
command('tabnew')
|
|
|
|
local tabnr = api.nvim_get_current_tabpage()
|
|
|
|
command('tabprev') -- return to the initial tab
|
|
|
|
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'right',
|
|
|
|
win = api.nvim_tabpage_get_win(tabnr),
|
|
|
|
})
|
|
|
|
|
|
|
|
eq(tabnr, api.nvim_win_get_tabpage(win))
|
|
|
|
-- we are changing the config, the current tabpage should not change
|
|
|
|
eq(curtab, api.nvim_get_current_tabpage())
|
|
|
|
|
|
|
|
command('tabnext') -- switch to the new tabpage so we can get the layout
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
|
|
|
|
eq({
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', api.nvim_tabpage_get_win(tabnr) },
|
|
|
|
{ 'leaf', win },
|
|
|
|
},
|
|
|
|
}, layout)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('correctly moves curwin when moving curwin to a different tabpage', function()
|
|
|
|
local curtab = api.nvim_get_current_tabpage()
|
|
|
|
command('tabnew')
|
|
|
|
local tab2 = api.nvim_get_current_tabpage()
|
|
|
|
local tab2_win = api.nvim_get_current_win()
|
|
|
|
|
|
|
|
command('tabprev') -- return to the initial tab
|
|
|
|
|
|
|
|
local neighbor = api.nvim_get_current_win()
|
|
|
|
|
|
|
|
-- create and enter a new split
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = false,
|
|
|
|
})
|
|
|
|
|
|
|
|
eq(curtab, api.nvim_win_get_tabpage(win))
|
|
|
|
|
|
|
|
eq({ win, neighbor }, api.nvim_tabpage_list_wins(curtab))
|
|
|
|
|
|
|
|
-- move the current win to a different tabpage
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'right',
|
|
|
|
win = api.nvim_tabpage_get_win(tab2),
|
|
|
|
})
|
|
|
|
|
|
|
|
eq(curtab, api.nvim_get_current_tabpage())
|
|
|
|
|
|
|
|
-- win should have moved to tab2
|
|
|
|
eq(tab2, api.nvim_win_get_tabpage(win))
|
|
|
|
-- tp_curwin of tab2 should not have changed
|
|
|
|
eq(tab2_win, api.nvim_tabpage_get_win(tab2))
|
|
|
|
-- win lists should be correct
|
|
|
|
eq({ tab2_win, win }, api.nvim_tabpage_list_wins(tab2))
|
|
|
|
eq({ neighbor }, api.nvim_tabpage_list_wins(curtab))
|
|
|
|
|
|
|
|
-- current win should have moved to neighboring win
|
|
|
|
eq(neighbor, api.nvim_tabpage_get_win(curtab))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('splits windows in non-current tabpage', function()
|
|
|
|
local curtab = api.nvim_get_current_tabpage()
|
|
|
|
command('tabnew')
|
|
|
|
local tabnr = api.nvim_get_current_tabpage()
|
|
|
|
command('tabprev') -- return to the initial tab
|
|
|
|
|
|
|
|
local win = api.nvim_open_win(0, false, {
|
|
|
|
vertical = false,
|
|
|
|
win = api.nvim_tabpage_get_win(tabnr),
|
|
|
|
})
|
|
|
|
|
|
|
|
eq(tabnr, api.nvim_win_get_tabpage(win))
|
|
|
|
-- since enter = false, the current tabpage should not change
|
|
|
|
eq(curtab, api.nvim_get_current_tabpage())
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('moves the current split window', function()
|
|
|
|
local initial_win = api.nvim_get_current_win()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = true,
|
|
|
|
})
|
|
|
|
local win2 = api.nvim_open_win(0, true, {
|
|
|
|
vertical = true,
|
|
|
|
})
|
|
|
|
api.nvim_set_current_win(win)
|
|
|
|
eq({
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', win2 },
|
|
|
|
{ 'leaf', win },
|
|
|
|
{ 'leaf', initial_win },
|
|
|
|
},
|
|
|
|
}, fn.winlayout())
|
|
|
|
|
|
|
|
api.nvim_win_set_config(0, {
|
|
|
|
vertical = false,
|
|
|
|
win = 0,
|
|
|
|
})
|
|
|
|
eq(win, api.nvim_get_current_win())
|
|
|
|
eq({
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win },
|
|
|
|
{
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', win2 },
|
|
|
|
{ 'leaf', initial_win },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, fn.winlayout())
|
|
|
|
|
|
|
|
api.nvim_set_current_win(win2)
|
|
|
|
local win3 = api.nvim_open_win(0, true, {
|
|
|
|
vertical = true,
|
|
|
|
})
|
|
|
|
eq(win3, api.nvim_get_current_win())
|
|
|
|
|
|
|
|
eq({
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win },
|
|
|
|
{
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', win3 },
|
|
|
|
{ 'leaf', win2 },
|
|
|
|
{ 'leaf', initial_win },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, fn.winlayout())
|
|
|
|
|
|
|
|
api.nvim_win_set_config(0, {
|
|
|
|
vertical = false,
|
|
|
|
win = 0,
|
|
|
|
})
|
|
|
|
|
|
|
|
eq(win3, api.nvim_get_current_win())
|
|
|
|
eq({
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win },
|
|
|
|
{
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win3 },
|
|
|
|
{ 'leaf', win2 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{ 'leaf', initial_win },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, fn.winlayout())
|
|
|
|
end)
|
2024-02-03 17:42:36 -07:00
|
|
|
|
|
|
|
it('closing new curwin when moving window to other tabpage works', function()
|
|
|
|
command('split | tabnew')
|
|
|
|
local w = api.nvim_get_current_win()
|
|
|
|
local t = api.nvim_get_current_tabpage()
|
2024-02-03 18:50:49 -07:00
|
|
|
command('tabfirst | autocmd WinEnter * quit')
|
2024-02-03 17:42:36 -07:00
|
|
|
api.nvim_win_set_config(0, { win = w, split = 'left' })
|
|
|
|
-- New tabpage is now the only one, as WinEnter closed the new curwin in the original.
|
|
|
|
eq(t, api.nvim_get_current_tabpage())
|
|
|
|
eq({ t }, api.nvim_list_tabpages())
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('closing split parent when moving window to other tabpage aborts', function()
|
|
|
|
command('split | tabnew')
|
|
|
|
local w = api.nvim_get_current_win()
|
|
|
|
command('tabfirst | autocmd WinEnter * call nvim_win_close(' .. w .. ', 1)')
|
|
|
|
eq(
|
|
|
|
'Window to split was closed',
|
|
|
|
pcall_err(api.nvim_win_set_config, 0, { win = w, split = 'left' })
|
|
|
|
)
|
|
|
|
end)
|
2024-02-03 18:50:49 -07:00
|
|
|
|
|
|
|
it('expected autocmds when moving window to other tabpage', function()
|
|
|
|
local new_curwin = api.nvim_get_current_win()
|
|
|
|
command('split')
|
|
|
|
local win = api.nvim_get_current_win()
|
|
|
|
command('tabnew')
|
|
|
|
local parent = api.nvim_get_current_win()
|
|
|
|
exec([[
|
|
|
|
tabfirst
|
|
|
|
let result = []
|
|
|
|
autocmd WinEnter * let result += ["Enter", win_getid()]
|
|
|
|
autocmd WinLeave * let result += ["Leave", win_getid()]
|
|
|
|
autocmd WinNew * let result += ["New", win_getid()]
|
|
|
|
]])
|
|
|
|
api.nvim_win_set_config(0, { win = parent, split = 'left' })
|
|
|
|
-- Shouldn't see WinNew, as we're not creating any new windows, just moving existing ones.
|
|
|
|
eq({ 'Leave', win, 'Enter', new_curwin }, eval('result'))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('no autocmds when moving window within same tabpage', function()
|
|
|
|
local parent = api.nvim_get_current_win()
|
|
|
|
exec([[
|
|
|
|
split
|
|
|
|
let result = []
|
|
|
|
autocmd WinEnter * let result += ["Enter", win_getid()]
|
|
|
|
autocmd WinLeave * let result += ["Leave", win_getid()]
|
|
|
|
autocmd WinNew * let result += ["New", win_getid()]
|
|
|
|
]])
|
|
|
|
api.nvim_win_set_config(0, { win = parent, split = 'left' })
|
|
|
|
-- Shouldn't see any of those events, as we remain in the same window.
|
|
|
|
eq({}, eval('result'))
|
|
|
|
end)
|
2024-02-07 10:17:44 -07:00
|
|
|
|
|
|
|
it('checks if splitting disallowed', function()
|
|
|
|
command('split | autocmd WinEnter * ++once call nvim_win_set_config(0, #{split: "right"})')
|
|
|
|
matches("E242: Can't split a window while closing another$", pcall_err(command, 'quit'))
|
|
|
|
|
|
|
|
command('autocmd BufHidden * ++once call nvim_win_set_config(0, #{split: "left"})')
|
|
|
|
matches(
|
|
|
|
'E1159: Cannot split a window when closing the buffer$',
|
|
|
|
pcall_err(command, 'new | quit')
|
|
|
|
)
|
|
|
|
|
|
|
|
-- OK when using window to different buffer.
|
|
|
|
local w = api.nvim_get_current_win()
|
|
|
|
command('autocmd BufHidden * ++once call nvim_win_set_config(' .. w .. ', #{split: "left"})')
|
|
|
|
command('new | quit')
|
|
|
|
end)
|
2021-05-27 14:10:42 -07:00
|
|
|
end)
|
2021-04-19 16:47:42 -07:00
|
|
|
|
|
|
|
describe('get_config', function()
|
|
|
|
it('includes border', function()
|
|
|
|
local b = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }
|
2024-01-12 10:59:57 -07:00
|
|
|
local win = api.nvim_open_win(0, true, {
|
2023-09-22 02:56:05 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
border = b,
|
2021-04-19 16:47:42 -07:00
|
|
|
})
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
local cfg = api.nvim_win_get_config(win)
|
2021-04-19 16:47:42 -07:00
|
|
|
eq(b, cfg.border)
|
|
|
|
end)
|
2023-09-22 02:56:05 -07:00
|
|
|
|
2021-04-19 16:47:42 -07:00
|
|
|
it('includes border with highlight group', function()
|
|
|
|
local b = {
|
|
|
|
{ 'a', 'Normal' },
|
|
|
|
{ 'b', 'Special' },
|
|
|
|
{ 'c', 'String' },
|
|
|
|
{ 'd', 'Comment' },
|
|
|
|
{ 'e', 'Visual' },
|
|
|
|
{ 'f', 'Error' },
|
|
|
|
{ 'g', 'Constant' },
|
|
|
|
{ 'h', 'PreProc' },
|
|
|
|
}
|
2024-01-12 10:59:57 -07:00
|
|
|
local win = api.nvim_open_win(0, true, {
|
2023-09-22 02:56:05 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
border = b,
|
2021-04-19 16:47:42 -07:00
|
|
|
})
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
local cfg = api.nvim_win_get_config(win)
|
2021-04-19 16:47:42 -07:00
|
|
|
eq(b, cfg.border)
|
|
|
|
end)
|
2023-09-22 02:56:05 -07:00
|
|
|
|
|
|
|
it('includes title and footer', function()
|
|
|
|
local title = { { 'A', { 'StatusLine', 'TabLine' } }, { 'B' }, { 'C', 'WinBar' } }
|
|
|
|
local footer = { { 'A', 'WinBar' }, { 'B' }, { 'C', { 'StatusLine', 'TabLine' } } }
|
2024-01-12 10:59:57 -07:00
|
|
|
local win = api.nvim_open_win(0, true, {
|
2023-09-22 02:56:05 -07:00
|
|
|
relative = 'win',
|
|
|
|
row = 3,
|
|
|
|
col = 3,
|
|
|
|
width = 12,
|
|
|
|
height = 3,
|
|
|
|
border = 'single',
|
|
|
|
title = title,
|
|
|
|
footer = footer,
|
|
|
|
})
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
local cfg = api.nvim_win_get_config(win)
|
2023-09-22 02:56:05 -07:00
|
|
|
eq(title, cfg.title)
|
|
|
|
eq(footer, cfg.footer)
|
|
|
|
end)
|
2024-01-31 20:43:35 -07:00
|
|
|
|
|
|
|
it('includes split for normal windows', function()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
vertical = true,
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
eq('left', api.nvim_win_get_config(win).split)
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
vertical = false,
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
eq('above', api.nvim_win_get_config(win).split)
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'below',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
eq('below', api.nvim_win_get_config(win).split)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('includes split when splitting with ex commands', function()
|
|
|
|
local win = api.nvim_get_current_win()
|
|
|
|
eq('left', api.nvim_win_get_config(win).split)
|
|
|
|
|
|
|
|
command('vsplit')
|
|
|
|
local win2 = api.nvim_get_current_win()
|
|
|
|
|
|
|
|
-- initial window now be marked as right split
|
|
|
|
-- since it was split with a vertical split
|
|
|
|
-- and 'splitright' is false by default
|
|
|
|
eq('right', api.nvim_win_get_config(win).split)
|
|
|
|
eq('left', api.nvim_win_get_config(win2).split)
|
|
|
|
|
|
|
|
api.nvim_set_option_value('splitbelow', true, {
|
|
|
|
scope = 'global',
|
|
|
|
})
|
|
|
|
api.nvim_win_close(win, true)
|
|
|
|
command('split')
|
|
|
|
local win3 = api.nvim_get_current_win()
|
|
|
|
eq('below', api.nvim_win_get_config(win3).split)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("includes the correct 'split' option in complex layouts", function()
|
|
|
|
local initial_win = api.nvim_get_current_win()
|
|
|
|
local win = api.nvim_open_win(0, false, {
|
|
|
|
split = 'right',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
|
|
|
|
local win2 = api.nvim_open_win(0, false, {
|
|
|
|
split = 'below',
|
|
|
|
win = win,
|
|
|
|
})
|
|
|
|
|
|
|
|
api.nvim_win_set_config(win2, {
|
|
|
|
width = 50,
|
|
|
|
})
|
|
|
|
|
|
|
|
api.nvim_win_set_config(win, {
|
|
|
|
split = 'left',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
|
|
|
|
local win3 = api.nvim_open_win(0, false, {
|
|
|
|
split = 'above',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
local float = api.nvim_open_win(0, false, {
|
|
|
|
relative = 'editor',
|
|
|
|
width = 40,
|
|
|
|
height = 20,
|
|
|
|
col = 20,
|
|
|
|
row = 10,
|
|
|
|
})
|
|
|
|
api.nvim_win_set_config(float, {
|
|
|
|
split = 'right',
|
|
|
|
win = -1,
|
|
|
|
})
|
|
|
|
|
|
|
|
local layout = fn.winlayout()
|
|
|
|
|
|
|
|
eq({
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{
|
|
|
|
'col',
|
|
|
|
{
|
|
|
|
{ 'leaf', win3 },
|
|
|
|
{
|
|
|
|
'row',
|
|
|
|
{
|
|
|
|
{ 'leaf', win },
|
|
|
|
{ 'leaf', initial_win },
|
|
|
|
{ 'leaf', win2 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'leaf',
|
|
|
|
float,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, layout)
|
|
|
|
|
|
|
|
eq('above', api.nvim_win_get_config(win3).split)
|
|
|
|
eq('left', api.nvim_win_get_config(win).split)
|
|
|
|
eq('left', api.nvim_win_get_config(initial_win).split)
|
|
|
|
eq('right', api.nvim_win_get_config(win2).split)
|
|
|
|
eq('right', api.nvim_win_get_config(float).split)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('set_config', function()
|
|
|
|
it('no crash with invalid title', function()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
title = { { 'test' } },
|
|
|
|
border = 'single',
|
|
|
|
})
|
|
|
|
eq(
|
|
|
|
'title/footer cannot be an empty array',
|
|
|
|
pcall_err(api.nvim_win_set_config, win, { title = {} })
|
|
|
|
)
|
|
|
|
command('redraw!')
|
|
|
|
assert_alive()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('no crash with invalid footer', function()
|
|
|
|
local win = api.nvim_open_win(0, true, {
|
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
footer = { { 'test' } },
|
|
|
|
border = 'single',
|
|
|
|
})
|
|
|
|
eq(
|
|
|
|
'title/footer cannot be an empty array',
|
|
|
|
pcall_err(api.nvim_win_set_config, win, { footer = {} })
|
|
|
|
)
|
|
|
|
command('redraw!')
|
|
|
|
assert_alive()
|
|
|
|
end)
|
2021-04-19 16:47:42 -07:00
|
|
|
end)
|
2023-12-16 06:58:04 -07:00
|
|
|
|
|
|
|
describe('set_config', function()
|
|
|
|
it('no crash with invalid title', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local win = api.nvim_open_win(0, true, {
|
2023-12-16 06:58:04 -07:00
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
title = { { 'test' } },
|
|
|
|
border = 'single',
|
|
|
|
})
|
|
|
|
eq(
|
|
|
|
'title/footer cannot be an empty array',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_set_config, win, { title = {} })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-12-16 06:58:04 -07:00
|
|
|
command('redraw!')
|
|
|
|
assert_alive()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('no crash with invalid footer', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local win = api.nvim_open_win(0, true, {
|
2023-12-16 06:58:04 -07:00
|
|
|
width = 10,
|
|
|
|
height = 10,
|
|
|
|
relative = 'editor',
|
|
|
|
row = 10,
|
|
|
|
col = 10,
|
|
|
|
footer = { { 'test' } },
|
|
|
|
border = 'single',
|
|
|
|
})
|
|
|
|
eq(
|
|
|
|
'title/footer cannot be an empty array',
|
2024-01-12 10:59:57 -07:00
|
|
|
pcall_err(api.nvim_win_set_config, win, { footer = {} })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-12-16 06:58:04 -07:00
|
|
|
command('redraw!')
|
|
|
|
assert_alive()
|
|
|
|
end)
|
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|