mirror of
https://github.com/neovim/neovim.git
synced 2025-12-11 09:02:40 +00:00
api: add vim.api.nvim_win_hide
This commit is contained in:
@@ -492,6 +492,30 @@ Dictionary nvim_win_get_config(Window window, Error *err)
|
||||
return rv;
|
||||
}
|
||||
|
||||
/// Hides the window (like |:hide| with a |window-ID|).
|
||||
///
|
||||
/// @param window Window handle, or 0 for current window
|
||||
/// @param[out] err Error details, if any
|
||||
void nvim_win_hide(Window window, Error *err)
|
||||
FUNC_API_SINCE(7)
|
||||
FUNC_API_CHECK_TEXTLOCK
|
||||
{
|
||||
win_T *win = find_window_by_handle(window, err);
|
||||
if (!win) {
|
||||
return;
|
||||
}
|
||||
|
||||
tabpage_T *tabpage = win_find_tabpage(win);
|
||||
TryState tstate;
|
||||
try_enter(&tstate);
|
||||
if (tabpage == curtab) {
|
||||
win_close(win, false);
|
||||
} else {
|
||||
win_close_othertab(win, false, tabpage);
|
||||
}
|
||||
vim_ignored = try_leave(&tstate, err);
|
||||
}
|
||||
|
||||
/// Closes the window (like |:close| with a |window-ID|).
|
||||
///
|
||||
/// @param window Window handle, or 0 for current window
|
||||
|
||||
@@ -347,4 +347,44 @@ describe('API/win', function()
|
||||
eq('', funcs.getcmdwintype())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('hide', function()
|
||||
it('can hide current window', function()
|
||||
local oldwin = meths.get_current_win()
|
||||
command('split')
|
||||
local newwin = meths.get_current_win()
|
||||
meths.win_hide(newwin)
|
||||
eq({oldwin}, meths.list_wins())
|
||||
end)
|
||||
it('can hide noncurrent window', function()
|
||||
local oldwin = meths.get_current_win()
|
||||
command('split')
|
||||
local newwin = meths.get_current_win()
|
||||
meths.win_hide(oldwin)
|
||||
eq({newwin}, meths.list_wins())
|
||||
end)
|
||||
it('does not close the buffer', function()
|
||||
local oldwin = meths.get_current_win()
|
||||
local oldbuf = meths.get_current_buf()
|
||||
local buf = meths.create_buf(true, false)
|
||||
local newwin = meths.open_win(buf, true, {
|
||||
relative='win', row=3, col=3, width=12, height=3
|
||||
})
|
||||
meths.win_hide(newwin)
|
||||
eq({oldwin}, meths.list_wins())
|
||||
eq({oldbuf, buf}, meths.list_bufs())
|
||||
end)
|
||||
it('deletes the buffer when bufhidden=wipe', function()
|
||||
local oldwin = meths.get_current_win()
|
||||
local oldbuf = meths.get_current_buf()
|
||||
local buf = meths.create_buf(true, false)
|
||||
local newwin = meths.open_win(buf, true, {
|
||||
relative='win', row=3, col=3, width=12, height=3
|
||||
})
|
||||
meths.buf_set_option(buf, 'bufhidden', 'wipe')
|
||||
meths.win_hide(newwin)
|
||||
eq({oldwin}, meths.list_wins())
|
||||
eq({oldbuf}, meths.list_bufs())
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user