aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ui/float_spec.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-23 18:55:11 +0800
committerGitHub <noreply@github.com>2023-01-23 18:55:11 +0800
commit0371d0f7afa5e01dd2ac8bbd3abcf0f7454872b3 (patch)
treea12edba6f135a7b2ca9fa49f9c95f09d1a56f12e /test/functional/ui/float_spec.lua
parentd58bf4ff307060829ba01f41dca52416105243d3 (diff)
downloadrneovim-0371d0f7afa5e01dd2ac8bbd3abcf0f7454872b3.tar.gz
rneovim-0371d0f7afa5e01dd2ac8bbd3abcf0f7454872b3.tar.bz2
rneovim-0371d0f7afa5e01dd2ac8bbd3abcf0f7454872b3.zip
refactor(win_close): remove "force", don't pass on "free_buf" (#21921)
Problem: The "force" flag of win_close() complicates the code and adds edge cases where it is not clear what the correct behavior should be. The "free_buf" flag of win_close() is passed on to float windows when closing the last window of a tabpage, which doesn't make much sense. Solution: Remove the "force" flag and always close float windows as if :close! is used when closing the last window of a tabpage, and set the "free_buf" flag for a float window based on whether its buffer can be freed. As 'hidden' is on by default, this change shouldn't affect many people.
Diffstat (limited to 'test/functional/ui/float_spec.lua')
-rw-r--r--test/functional/ui/float_spec.lua46
1 files changed, 24 insertions, 22 deletions
diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua
index 6759510ad1..60952543e7 100644
--- a/test/functional/ui/float_spec.lua
+++ b/test/functional/ui/float_spec.lua
@@ -462,6 +462,9 @@ describe('float window', function()
end)
end)
describe("deleting the last non-floating window's buffer", function()
+ after_each(function()
+ eq(false, meths.buf_is_valid(old_buf))
+ end)
describe('leaves one window with an empty buffer when there is only one buffer', function()
local same_buf_float
before_each(function()
@@ -552,6 +555,9 @@ describe('float window', function()
end)
end)
describe('with splits, deleting the last listed buffer creates an empty buffer', function()
+ after_each(function()
+ eq(false, meths.buf_is_valid(old_buf))
+ end)
describe('when a non-floating window has an unlisted buffer', function()
local same_buf_float
before_each(function()
@@ -597,6 +603,7 @@ describe('float window', function()
same_buf_float = meths.open_win(old_buf, false, float_opts).id
end)
after_each(function()
+ eq(false, meths.buf_is_valid(old_buf))
expect('')
eq(2, #meths.list_wins())
eq(2, #meths.list_tabpages())
@@ -629,6 +636,7 @@ describe('float window', function()
same_buf_float = meths.open_win(old_buf, false, float_opts).id
end)
after_each(function()
+ eq(false, meths.buf_is_valid(old_buf))
expect('')
eq(3, #meths.list_wins())
eq(2, #meths.list_tabpages())
@@ -656,12 +664,18 @@ describe('float window', function()
old_win = curwin().id
end)
describe('closing the last non-floating window', function()
- describe('closes the tabpage when all floating windows are closeable', function()
- local same_buf_float
+ describe('closes the tabpage force-closing floating windows', function()
+ local same_buf_float, other_buf, other_buf_float
before_each(function()
+ command('set nohidden')
same_buf_float = meths.open_win(old_buf, false, float_opts).id
+ other_buf = meths.create_buf(true, false).id
+ other_buf_float = meths.open_win(other_buf, true, float_opts).id
+ insert('foo')
+ meths.set_current_win(old_win)
end)
after_each(function()
+ eq(true, meths.buf_is_valid(other_buf))
eq(old_tabpage, curtab().id)
expect('oldtab')
eq(1, #meths.list_tabpages())
@@ -669,41 +683,30 @@ describe('float window', function()
it('if called from non-floating window', function()
meths.win_close(old_win, false)
end)
- it('if called from floating window', function()
+ it('if called from floating window with the same buffer', function()
meths.set_current_win(same_buf_float)
meths.win_close(old_win, false)
end)
- end)
- describe('gives E5601 when there are non-closeable floating windows', function()
- local other_buf_float
- before_each(function()
- command('set nohidden')
- local other_buf = meths.create_buf(true, false).id
- other_buf_float = meths.open_win(other_buf, true, float_opts).id
- insert('foo')
- meths.set_current_win(old_win)
- end)
- it('if called from non-floating window', function()
- eq('Vim:E5601: Cannot close window, only floating window would remain',
- pcall_err(meths.win_close, old_win, false))
- end)
- it('if called from floating window', function()
+ it('if called from floating window with another buffer', function()
meths.set_current_win(other_buf_float)
- eq('Vim:E5601: Cannot close window, only floating window would remain',
- pcall_err(meths.win_close, old_win, false))
+ meths.win_close(old_win, false)
end)
end)
end)
describe("deleting the last non-floating window's buffer", function()
- describe('closes the tabpage when all floating windows are closeable', function()
+ describe('closes the tabpage force-closing floating windows', function()
local same_buf_float, other_buf, other_buf_float
before_each(function()
+ command('set nohidden')
same_buf_float = meths.open_win(old_buf, false, float_opts).id
other_buf = meths.create_buf(true, false).id
other_buf_float = meths.open_win(other_buf, true, float_opts).id
+ insert('foo')
meths.set_current_win(old_win)
end)
after_each(function()
+ eq(false, meths.buf_is_valid(old_buf))
+ eq(true, meths.buf_is_valid(other_buf))
eq(old_tabpage, curtab().id)
expect('oldtab')
eq(1, #meths.list_tabpages())
@@ -721,7 +724,6 @@ describe('float window', function()
meths.buf_delete(old_buf, {force = false})
end)
end)
- -- TODO: what to do when there are non-closeable floating windows?
end)
end)