From 66f331fef7ad3df480bd02f1705e176d1a07c785 Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Fri, 23 Feb 2024 09:49:28 +0000 Subject: vim-patch:9.1.0116: win_split_ins may not check available room Problem: win_split_ins has no check for E36 when moving an existing window Solution: check for room and fix the issues in f_win_splitmove() (Sean Dewar) https://github.com/vim/vim/commit/0fd44a5ad81ade342cb54d8984965bdedd2272c8 Omit WSP_FORCE_ROOM, as it's not needed for Nvim's autocmd window, which is floating. Shouldn't be difficult to port later if it's used for anything else. Make win_splitmove continue working for turning floating windows into splits. Move the logic for "unfloating" a float to win_split_ins; unlike splits, no changes to the window layout are needed before calling it, as floats take no room in the window layout and cannot affect the e_noroom check. Add missing tp_curwin-fixing logic for turning external windows into splits, and add a test. NOTE: there are other issues with the way "tabpage independence" is implemented for external windows; namely, some things assume that tp_curwin is indeed a window within that tabpage, and as such, functions like tabpage_winnr and nvim_tabpage_get_win currently don't always work for external windows (with the latter aborting!) Use last_status over frame_add_statusline, as Nvim's last_status already does this for all windows in the current tabpage. Adjust restore_full_snapshot_rec to handle this. This "restore everything" approach is changed in a future commit anyway, so only ensure it's robust enough to just pass tests. Keep check_split_disallowed's current doc comment, as it's actually a bit more accurate here. (I should probably PR Vim to use this one) Allow f_win_splitmove to move a floating "wp" into a split; Nvim supports this. Continue to disallow it from moving the autocommand window into a split (funnily enough, the check wasn't reachable before, as moving a float was disallowed), but now return -1 in that case (win_splitmove also returns FAIL for this, but handling it in f_win_splitmove avoids us needing to switch windows first). Cherry-pick Test_window_split_no_room fix from v9.1.0121. Update nvim_win_set_config to handle win_split_ins failure in later commits. --- test/functional/ui/float_spec.lua | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index cdb3b79963..e324d03b30 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -550,6 +550,43 @@ describe('float window', function() eq({ w0 }, api.nvim_list_wins()) end) + it('win_splitmove() can move float into a split', function() + command('split') + eq({'col', {{'leaf', 1001}, {'leaf', 1000}}}, fn.winlayout()) + + local win1 = api.nvim_open_win(0, true, {relative = 'editor', row = 1, col = 1, width = 5, height = 5}) + fn.win_splitmove(win1, 1001, {vertical = true}) + eq({'col', {{'row', {{'leaf', win1}, {'leaf', 1001}}}, {'leaf', 1000}}}, fn.winlayout()) + eq('', api.nvim_win_get_config(win1).relative) + + -- Should be unable to create a split relative to a float, though. + local win2 = api.nvim_open_win(0, true, {relative = 'editor', row = 1, col = 1, width = 5, height = 5}) + eq('Vim:E957: Invalid window number', pcall_err(fn.win_splitmove, win1, win2, {vertical = true})) + end) + + it('tp_curwin updated if external window is moved into split', function() + local screen = Screen.new(20, 7) + screen:attach { ext_multigrid = true } + + command('tabnew') + local external_win = api.nvim_open_win(0, true, {external = true, width = 5, height = 5}) + eq(external_win, api.nvim_get_current_win()) + eq(2, fn.tabpagenr()) + command('tabfirst') + api.nvim_set_current_win(external_win) + eq(external_win, api.nvim_get_current_win()) + eq(1, fn.tabpagenr()) + + command('wincmd J') + eq(external_win, api.nvim_get_current_win()) + eq(false, api.nvim_win_get_config(external_win).external) + command('tabnext') + eq(2, fn.tabpagenr()) + neq(external_win, api.nvim_get_current_win()) + + screen:detach() + end) + describe('with only one tabpage,', function() local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} local old_buf, old_win @@ -9101,6 +9138,22 @@ describe('float window', function() ]]} end end) + + it('attempt to turn into split with no room', function() + eq('Vim(split):E36: Not enough room', pcall_err(command, 'execute "split |"->repeat(&lines)')) + command('vsplit | wincmd | | wincmd p') + api.nvim_open_win(0, true, {relative = "editor", row = 0, col = 0, width = 5, height = 5}) + local config = api.nvim_win_get_config(0) + eq('editor', config.relative) + + local layout = fn.winlayout() + local restcmd = fn.winrestcmd() + eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd K')) + eq('Vim(wincmd):E36: Not enough room', pcall_err(command, 'wincmd J')) + eq(layout, fn.winlayout()) + eq(restcmd, fn.winrestcmd()) + eq(config, api.nvim_win_get_config(0)) + end) end describe('with ext_multigrid', function() -- cgit From 33dfb5a383d7afacda35b8fd392ad18d57db2870 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Mar 2024 12:47:40 +0800 Subject: fix(window): :close may cause Nvim to quit with autocmd and float Problem: :close may cause Nvim to quit if an autocommand triggered when closing the buffer closes all other non-floating windows and there are floating windows. Solution: Correct the check for the only non-floating window. --- test/functional/ui/float_spec.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index e324d03b30..8b7107fdf2 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -873,6 +873,39 @@ describe('float window', function() end) end) + describe(':close on non-float with floating windows', function() + it('does not quit Nvim if BufWinLeave makes it the only non-float', function() + exec([[ + let firstbuf = bufnr() + new + let midwin = win_getid() + new + setlocal bufhidden=wipe + call nvim_win_set_config(midwin, + \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5}) + autocmd BufWinLeave * ++once exe firstbuf .. 'bwipe!' + ]]) + eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close')) + assert_alive() + end) + + pending('does not crash if BufWinLeave makes it the only non-float in tabpage', function() + exec([[ + tabnew + let firstbuf = bufnr() + new + let midwin = win_getid() + new + setlocal bufhidden=wipe + call nvim_win_set_config(midwin, + \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5}) + autocmd BufWinLeave * ++once exe firstbuf .. 'bwipe!' + ]]) + eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close')) + assert_alive() + end) + end) + local function with_ext_multigrid(multigrid) local screen, attrs before_each(function() -- cgit From 731e7f51ee40778b5baeec99aaf1d551b0855667 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 10 Mar 2024 07:55:04 +0800 Subject: fix(window): :close crash with autocmd, floats and tabpage (#27793) Problem: :close crash with autocmd, floats and tabpage. Solution: Close floating windows in one more case. --- test/functional/ui/float_spec.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 8b7107fdf2..50b4b3b073 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -874,34 +874,38 @@ describe('float window', function() end) describe(':close on non-float with floating windows', function() + -- XXX: it isn't really clear whether this should quit Nvim, as if the autocommand + -- here is BufUnload then it does quit Nvim. + -- But with BufWinLeave, this doesn't quit Nvim if there are no floating windows, + -- so it shouldn't quit Nvim if there are floating windows. it('does not quit Nvim if BufWinLeave makes it the only non-float', function() exec([[ - let firstbuf = bufnr() + let g:buf = bufnr() new - let midwin = win_getid() + let s:midwin = win_getid() new setlocal bufhidden=wipe - call nvim_win_set_config(midwin, + call nvim_win_set_config(s:midwin, \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5}) - autocmd BufWinLeave * ++once exe firstbuf .. 'bwipe!' + autocmd BufWinLeave * ++once exe g:buf .. 'bwipe!' ]]) eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close')) assert_alive() end) - pending('does not crash if BufWinLeave makes it the only non-float in tabpage', function() + it('does not crash if BufUnload makes it the only non-float in tabpage', function() exec([[ tabnew - let firstbuf = bufnr() + let g:buf = bufnr() new - let midwin = win_getid() + let s:midwin = win_getid() new setlocal bufhidden=wipe - call nvim_win_set_config(midwin, + call nvim_win_set_config(s:midwin, \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5}) - autocmd BufWinLeave * ++once exe firstbuf .. 'bwipe!' + autocmd BufUnload * ++once exe g:buf .. 'bwipe!' ]]) - eq('Vim(close):E855: Autocommands caused command to abort', pcall_err(command, 'close')) + command('close') assert_alive() end) end) -- cgit From 9bd4a2807960ea3e82b0454861b399f4ac6d8a92 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 10 Mar 2024 08:37:16 +0800 Subject: fix(window): :close crash if WinClosed from float closes window (#27794) Problem: :close crash if WinClosed from float closes window. Solution: Check if window has already been closed. --- test/functional/ui/float_spec.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 50b4b3b073..6bc3fd14ec 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -908,6 +908,21 @@ describe('float window', function() command('close') assert_alive() end) + + it('does not crash if WinClosed from floating windows closes it', function() + exec([[ + tabnew + let g:buf = bufnr() + new + let s:win = win_getid() + call nvim_win_set_config(s:win, + \ #{relative: 'editor', row: 5, col: 5, width: 5, height: 5}) + wincmd t + exe $"autocmd WinClosed {s:win} 1close" + ]]) + command('close') + assert_alive() + end) end) local function with_ext_multigrid(multigrid) -- cgit From 6052b346f1b7a3fb616dfcefe3bc05cb6fe3f2f3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 10 Mar 2024 10:33:10 +0800 Subject: revert: "fix(window): :close crash with autocmd, floats and tabpage" (#27796) This reverts PR #27793. On second thought, this solution may still crash, because it can leave a window with a NULL buffer if there are autocommand windows or if closing a floating window fails. It also makes close_last_window_tabpage() more complicated, so revert it. --- test/functional/ui/float_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 6bc3fd14ec..65a7d359af 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -893,7 +893,7 @@ describe('float window', function() assert_alive() end) - it('does not crash if BufUnload makes it the only non-float in tabpage', function() + pending('does not crash if BufUnload makes it the only non-float in tabpage', function() exec([[ tabnew let g:buf = bufnr() @@ -909,10 +909,9 @@ describe('float window', function() assert_alive() end) - it('does not crash if WinClosed from floating windows closes it', function() + it('does not crash if WinClosed from floating window closes it', function() exec([[ tabnew - let g:buf = bufnr() new let s:win = win_getid() call nvim_win_set_config(s:win, -- cgit From 1da0f3494eb042c84ae5f00654878f7f8cedf3b7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 11 Mar 2024 22:23:14 +0800 Subject: test: correct order of arguments to eq() (#27816) --- test/functional/ui/float_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 65a7d359af..361ea3e778 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -6257,7 +6257,7 @@ describe('float window', function() run(on_request, nil, on_setup) os.remove('Xtest_written') os.remove('Xtest_written2') - eq(exited, true) + eq(true, exited) end) it(':quit two floats in a row', function() -- cgit From 2e4e12756a697d4767ec294e1f268384395e7a7f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 28 Mar 2024 15:27:32 +0100 Subject: feat(ui): indicate margins for the area used by win_viewport Problem: using win_viewport for implementing smooth scrolling in an external UI might run into problems when winbar or borders is used, as there is no indication that the entire grid is not used for scrolled buffer text. Solution: add `win_viewport_margins` event. --- test/functional/ui/float_spec.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 361ea3e778..e83f3ff57e 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1536,7 +1536,12 @@ describe('float window', function() }, win_viewport={ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0}; - }} + }, + win_viewport_margins={ + [2] = {win = 1000, top = 0, bottom = 0, left = 0, right = 0}; + [4] = {win = 1001, top = 1, bottom = 1, left = 1, right = 1}; + } + } else screen:expect{grid=[[ ^ | @@ -1736,7 +1741,12 @@ describe('float window', function() }, win_viewport={ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0}; - }} + }, + win_viewport_margins={ + [2] = {win = 1000, top = 0, bottom = 0, left = 0, right = 0}; + [4] = {win = 1001, top = 0, bottom = 0, left = 1, right = 1}; + } + } else screen:expect{grid=[[ ^ | @@ -1769,6 +1779,10 @@ describe('float window', function() }, win_viewport={ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0}; + }, + win_viewport_margins={ + [2] = {win = 1000, top = 0, bottom = 0, left = 0, right = 0}; + [4] = {win = 1001, top = 1, bottom = 1, left = 0, right = 0}; }} else screen:expect{grid=[[ @@ -1814,6 +1828,10 @@ describe('float window', function() }, win_viewport={ [2] = {win = 1000, topline = 0, botline = 6, curline = 5, curcol = 0, linecount = 6, sum_scroll_delta = 0}; [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0}; + }, + win_viewport_margins={ + [2] = {win = 1000, top = 0, bottom = 0, left = 0, right = 0}; + [4] = {win = 1001, top = 0, bottom = 1, left = 0, right = 1}; }} else screen:expect{grid=[[ @@ -8361,6 +8379,10 @@ describe('float window', function() }, win_viewport={ [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + }, + win_viewport_margins={ + [2] = {win = 1000, top = 0, bottom = 0, left = 0, right = 0}; + [4] = {win = 1001, top = 2, bottom = 1, left = 1, right = 1}; }} else screen:expect{grid=[[ -- cgit From 7035125b2b26aa68fcfb7cda39377ac79926a0f9 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 8 Apr 2024 11:03:20 +0200 Subject: test: improve test conventions Work on https://github.com/neovim/neovim/issues/27004. --- test/functional/ui/float_spec.lua | 44 +++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index e83f3ff57e..79e62d487f 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1,24 +1,24 @@ -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) local Screen = require('test.functional.ui.screen') local os = require('os') -local clear, feed = helpers.clear, helpers.feed -local assert_alive = helpers.assert_alive -local command, feed_command = helpers.command, helpers.feed_command -local eval = helpers.eval -local eq = helpers.eq -local neq = helpers.neq -local expect = helpers.expect -local exec = helpers.exec -local exec_lua = helpers.exec_lua -local insert = helpers.insert -local api = helpers.api -local fn = helpers.fn -local run = helpers.run -local pcall_err = helpers.pcall_err +local clear, feed = t.clear, t.feed +local assert_alive = t.assert_alive +local command, feed_command = t.command, t.feed_command +local eval = t.eval +local eq = t.eq +local neq = t.neq +local expect = t.expect +local exec = t.exec +local exec_lua = t.exec_lua +local insert = t.insert +local api = t.api +local fn = t.fn +local run = t.run +local pcall_err = t.pcall_err local tbl_contains = vim.tbl_contains -local curbuf = helpers.api.nvim_get_current_buf -local curwin = helpers.api.nvim_get_current_win -local curtab = helpers.api.nvim_get_current_tabpage +local curbuf = t.api.nvim_get_current_buf +local curwin = t.api.nvim_get_current_win +local curtab = t.api.nvim_get_current_tabpage local NIL = vim.NIL describe('float window', function() @@ -4080,7 +4080,7 @@ describe('float window', function() if multigrid then pending("supports second UI without multigrid", function() - local session2 = helpers.connect(eval('v:servername')) + local session2 = t.connect(eval('v:servername')) print(session2:request("nvim_eval", "2+2")) local screen2 = Screen.new(40,7) screen2:attach(nil, session2) @@ -7978,7 +7978,7 @@ describe('float window', function() end) it("correctly redraws when overlaid windows are resized #13991", function() - helpers.source([[ + t.source([[ let popup_config = {"relative" : "editor", \ "width" : 7, \ "height" : 3, @@ -8042,7 +8042,7 @@ describe('float window', function() ]]) end - helpers.source([[ + t.source([[ let new_popup_config = {"width" : 1, "height" : 3} let new_border_config = {"width" : 3, "height" : 5} @@ -8057,7 +8057,7 @@ describe('float window', function() nnoremap zz call Resize() ]]) - helpers.feed("zz") + t.feed("zz") if multigrid then screen:expect{grid=[[ ## grid 1 -- cgit From 898371fc9faec605b11a17857a862991b722db51 Mon Sep 17 00:00:00 2001 From: glepnir Date: Thu, 28 Dec 2023 17:46:59 +0800 Subject: fix(float): don't relative flaot win itself Problem: when reconfig current float win without win key in nvim_win_set_config will cause float win position changed when move. Solution: don't relative itself. --- test/functional/ui/float_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 79e62d487f..eceb30039a 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -9227,6 +9227,14 @@ describe('float window', function() eq(restcmd, fn.winrestcmd()) eq(config, api.nvim_win_get_config(0)) end) + + it("error when relative to itself", function() + local buf = api.nvim_create_buf(false, true) + local config = { relative='win', width=5, height=2, row=3, col=3 } + local winid = api.nvim_open_win(buf, false, config) + api.nvim_set_current_win(winid) + eq("floating window cannot be relative to itself", pcall_err(api.nvim_win_set_config, winid, config)) + end) end describe('with ext_multigrid', function() -- cgit From 81fc27124b9e1b375e0ce9605ae69c3c2a2d9222 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 9 Apr 2024 12:26:16 +0100 Subject: refactor(test): inject after_each differently --- test/functional/ui/float_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 79e62d487f..a328adb2ce 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1,4 +1,4 @@ -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local Screen = require('test.functional.ui.screen') local os = require('os') local clear, feed = t.clear, t.feed -- cgit From 3ea124a8d9f08dd9f9af3bc0877f7b888a47f10b Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 13 Apr 2024 14:36:17 +0800 Subject: fix(float): improve error message when reconfig failed (#25076) Problem: The current error message isn't very accurate. Solution: Improve the error message. --- test/functional/ui/float_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 41b5b6ed2f..ed66557ee8 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -325,6 +325,27 @@ describe('float window', function() eq(12, pos[2]) end) + it('error message when reconfig missing relative field', function() + local bufnr = api.nvim_create_buf(false, true) + local opts = { + width = 10, + height = 10, + col = 5, + row = 5, + relative = 'editor', + style = 'minimal', + } + local win_id = api.nvim_open_win(bufnr, true, opts) + eq( + "Missing 'relative' field when reconfiguring floating window 1001", + pcall_err(api.nvim_win_set_config, win_id, { + width = 3, + height = 3, + row = 10, + col = 10, + })) + end) + it('is not operated on by windo when non-focusable #15374', function() command([[ let winids = [] -- cgit From 5f18dd30137565da782c155b52b530c172b3b29d Mon Sep 17 00:00:00 2001 From: glepnir Date: Sat, 20 Apr 2024 12:01:28 +0800 Subject: fix(float): wrong position when bufpos is set Problem: when lnum in bufpos is out of range the position of float is wired. Solution: avoid the height value out of buffer line range. --- test/functional/ui/float_spec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index ed66557ee8..f4e611b255 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -9256,6 +9256,43 @@ describe('float window', function() api.nvim_set_current_win(winid) eq("floating window cannot be relative to itself", pcall_err(api.nvim_win_set_config, winid, config)) end) + + it("bufpos out of range", function() + local buf = api.nvim_create_buf(false, true) + api.nvim_buf_set_lines(0, 0, -1, false, {}) + local config = { relative='win', width=5, height=2, row=0, col=0, bufpos = { 3, 3 } } + api.nvim_open_win(buf, false, config) + if multigrid then + screen:expect({ + grid = [[ + ## grid 1 + [2:----------------------------------------]|*6 + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }|*5 + ## grid 3 + | + ## grid 4 + {1: }| + {2:~ }| + ]], float_pos={ + [4] = {1001, "NW", 2, 0, 0, true, 50}; + }, win_viewport={ + [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + }}) + else + screen:expect({ + grid = [[ + {1:^ } | + {2:~ }{0: }| + {0:~ }|*4 + | + ]] + }) + end + end) end describe('with ext_multigrid', function() -- cgit From 2cbfa4b9af789303a434ecf62360ac247bfffc10 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 22 Apr 2024 17:57:49 +0800 Subject: fix(window): don't go to unfocusable float when closing (#28455) --- test/functional/ui/float_spec.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index ed66557ee8..d3a20ca021 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -434,6 +434,25 @@ describe('float window', function() eq(winid, eval('win_getid()')) end) + it('is not active after closing window when non-focusable #28454', function() + command('copen') + local winid = exec_lua([[ + local bufnr = vim.api.nvim_create_buf(false, true) + local opts = { + relative = 'editor', + focusable = false, + height = 5, + width = 5, + col = 5, + row = 5, + } + return vim.api.nvim_open_win(bufnr, false, opts) + ]]) + command('wincmd t') + command('wincmd q') + neq(winid, curwin()) + end) + it('supports windo with focusable and non-focusable floats', function() local winids = exec_lua([[ local result = {vim.api.nvim_get_current_win()} -- cgit From 052498ed42780a76daea589d063cd8947a894673 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 20 Apr 2024 17:44:13 +0200 Subject: test: improve test conventions Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004. --- test/functional/ui/float_spec.lua | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 99cb2e56f4..b7fb9dbd32 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -1,24 +1,26 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') local os = require('os') -local clear, feed = t.clear, t.feed -local assert_alive = t.assert_alive -local command, feed_command = t.command, t.feed_command -local eval = t.eval + +local clear, feed = n.clear, n.feed +local assert_alive = n.assert_alive +local command, feed_command = n.command, n.feed_command +local eval = n.eval local eq = t.eq local neq = t.neq -local expect = t.expect -local exec = t.exec -local exec_lua = t.exec_lua -local insert = t.insert -local api = t.api -local fn = t.fn -local run = t.run +local expect = n.expect +local exec = n.exec +local exec_lua = n.exec_lua +local insert = n.insert +local api = n.api +local fn = n.fn +local run = n.run local pcall_err = t.pcall_err local tbl_contains = vim.tbl_contains -local curbuf = t.api.nvim_get_current_buf -local curwin = t.api.nvim_get_current_win -local curtab = t.api.nvim_get_current_tabpage +local curbuf = n.api.nvim_get_current_buf +local curwin = n.api.nvim_get_current_win +local curtab = n.api.nvim_get_current_tabpage local NIL = vim.NIL describe('float window', function() @@ -4120,7 +4122,7 @@ describe('float window', function() if multigrid then pending("supports second UI without multigrid", function() - local session2 = t.connect(eval('v:servername')) + local session2 = n.connect(eval('v:servername')) print(session2:request("nvim_eval", "2+2")) local screen2 = Screen.new(40,7) screen2:attach(nil, session2) @@ -8018,7 +8020,7 @@ describe('float window', function() end) it("correctly redraws when overlaid windows are resized #13991", function() - t.source([[ + n.source([[ let popup_config = {"relative" : "editor", \ "width" : 7, \ "height" : 3, @@ -8082,7 +8084,7 @@ describe('float window', function() ]]) end - t.source([[ + n.source([[ let new_popup_config = {"width" : 1, "height" : 3} let new_border_config = {"width" : 3, "height" : 5} @@ -8097,7 +8099,7 @@ describe('float window', function() nnoremap zz call Resize() ]]) - t.feed("zz") + n.feed("zz") if multigrid then screen:expect{grid=[[ ## grid 1 -- cgit From 16513b30337523dc64707309ee7fe3dd2247266d Mon Sep 17 00:00:00 2001 From: Will Hopkins Date: Wed, 24 Apr 2024 18:14:05 -0700 Subject: feat(api): allow floats to be opened in non-current tabpage (#28480) \ --- test/functional/ui/float_spec.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index b7fb9dbd32..131cc15bfb 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -532,7 +532,10 @@ describe('float window', function() local closed_win = api.nvim_get_current_win() command('close') local buf = api.nvim_create_buf(false,false) - api.nvim_open_win(buf, true, {relative='win', win=closed_win, width=1, height=1, bufpos={0,0}}) + eq( + 'Invalid window id: ' .. closed_win, + pcall_err(api.nvim_open_win, buf, true, {relative='win', win=closed_win, width=1, height=1, bufpos={0,0}}) + ) assert_alive() end) -- cgit From 4e5c633ed4871a948aff7338b793ac5f93484153 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 12 May 2024 05:39:33 +0800 Subject: fix(api): make getting explicit empty hl in virtual text work (#28697) --- test/functional/ui/float_spec.lua | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test/functional/ui/float_spec.lua') diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 131cc15bfb..248220e28b 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -2407,6 +2407,7 @@ describe('float window', function() command('hi B0 guibg=Red guifg=Black') command('hi B1 guifg=White') + api.nvim_win_set_config(win, { title = {{"🦄"}, {"BB", {"B0", "B1"}}}, title_pos = "right", footer= {{"🦄"}, {"BB", {"B0", "B1"}}}, footer_pos = "right", @@ -2443,6 +2444,47 @@ describe('float window', function() | ]]} end + eq({{"🦄"}, {"BB", {"B0", "B1"}}}, api.nvim_win_get_config(win).title) + eq({{"🦄"}, {"BB", {"B0", "B1"}}}, api.nvim_win_get_config(win).footer) + + api.nvim_win_set_config(win, { + title = {{"🦄", ""}, {"BB", {"B0", "B1", ""}}}, title_pos = "left", + footer= {{"🦄", ""}, {"BB", {"B0", "B1", ""}}}, footer_pos = "left", + }) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]|*6 + [3:----------------------------------------]| + ## grid 2 + ^ | + {0:~ }|*5 + ## grid 3 + | + ## grid 4 + {5:╔}🦄{7:BB}{5:═════╗}| + {5:║}{1: halloj! }{5:║}| + {5:║}{1: BORDAA }{5:║}| + {5:╚}🦄{7:BB}{5:═════╝}| + ]], float_pos={ + [4] = { 1001, "NW", 1, 2, 5, true } + }, win_viewport={ + [2] = {win = 1000, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1, sum_scroll_delta = 0}; + [4] = {win = 1001, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2, sum_scroll_delta = 0}; + }} + else + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }{5:╔}🦄{7:BB}{5:═════╗}{0: }| + {0:~ }{5:║}{1: halloj! }{5:║}{0: }| + {0:~ }{5:║}{1: BORDAA }{5:║}{0: }| + {0:~ }{5:╚}🦄{7:BB}{5:═════╝}{0: }| + | + ]]} + end + eq({{"🦄", ""}, {"BB", {"B0", "B1", ""}}}, api.nvim_win_get_config(win).title) + eq({{"🦄", ""}, {"BB", {"B0", "B1", ""}}}, api.nvim_win_get_config(win).footer) end) it('terminates border on edge of viewport when window extends past viewport', function() -- cgit