mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #24457 from seandewar/relax-cmdwin
feat(api): relax cmdwin restrictions for a few functions
This commit is contained in:
commit
8fe9f41f7f
@ -2897,7 +2897,7 @@ nvim_win_hide({window}) *nvim_win_hide()*
|
|||||||
or |nvim_win_close()|, which will close the buffer.
|
or |nvim_win_close()|, which will close the buffer.
|
||||||
|
|
||||||
Attributes: ~
|
Attributes: ~
|
||||||
not allowed when |textlock| is active or in the |cmdwin|
|
not allowed when |textlock| is active
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {window} Window handle, or 0 for current window
|
• {window} Window handle, or 0 for current window
|
||||||
@ -2915,7 +2915,7 @@ nvim_win_set_buf({window}, {buffer}) *nvim_win_set_buf()*
|
|||||||
Sets the current buffer in a window, without side effects
|
Sets the current buffer in a window, without side effects
|
||||||
|
|
||||||
Attributes: ~
|
Attributes: ~
|
||||||
not allowed when |textlock| is active or in the |cmdwin|
|
not allowed when |textlock| is active
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {window} Window handle, or 0 for current window
|
• {window} Window handle, or 0 for current window
|
||||||
@ -3036,7 +3036,7 @@ nvim_open_win({buffer}, {enter}, {*config}) *nvim_open_win()*
|
|||||||
<
|
<
|
||||||
|
|
||||||
Attributes: ~
|
Attributes: ~
|
||||||
not allowed when |textlock| is active or in the |cmdwin|
|
not allowed when |textlock| is active
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {buffer} Buffer to display, or 0 for current buffer
|
• {buffer} Buffer to display, or 0 for current buffer
|
||||||
|
@ -967,7 +967,7 @@ Integer nvim_open_term(Buffer buffer, DictionaryOf(LuaRef) opts, Error *err)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cmdwin_type != 0 && buf == curbuf) {
|
if (cmdwin_type != 0 && buf == curbuf) {
|
||||||
api_set_error(err, kErrorTypeException, "%s", _(e_cmdwin));
|
api_set_error(err, kErrorTypeException, "%s", e_cmdwin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,8 +158,17 @@
|
|||||||
/// @return Window handle, or 0 on error
|
/// @return Window handle, or 0 on error
|
||||||
Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, Error *err)
|
Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, Error *err)
|
||||||
FUNC_API_SINCE(6)
|
FUNC_API_SINCE(6)
|
||||||
FUNC_API_TEXTLOCK
|
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
|
||||||
{
|
{
|
||||||
|
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||||
|
if (!buf) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (cmdwin_type != 0 && (enter || buf == curbuf)) {
|
||||||
|
api_set_error(err, kErrorTypeException, "%s", e_cmdwin);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
FloatConfig fconfig = FLOAT_CONFIG_INIT;
|
FloatConfig fconfig = FLOAT_CONFIG_INIT;
|
||||||
if (!parse_float_config(config, &fconfig, false, true, err)) {
|
if (!parse_float_config(config, &fconfig, false, true, err)) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -173,7 +182,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(float_config) *config, E
|
|||||||
}
|
}
|
||||||
// autocmds in win_enter or win_set_buf below may close the window
|
// autocmds in win_enter or win_set_buf below may close the window
|
||||||
if (win_valid(wp) && buffer > 0) {
|
if (win_valid(wp) && buffer > 0) {
|
||||||
win_set_buf(wp->handle, buffer, fconfig.noautocmd, err);
|
win_set_buf(wp, buf, fconfig.noautocmd, err);
|
||||||
}
|
}
|
||||||
if (!win_valid(wp)) {
|
if (!win_valid(wp)) {
|
||||||
api_set_error(err, kErrorTypeException, "Window was closed immediately");
|
api_set_error(err, kErrorTypeException, "Window was closed immediately");
|
||||||
|
@ -50,9 +50,18 @@ Buffer nvim_win_get_buf(Window window, Error *err)
|
|||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
void nvim_win_set_buf(Window window, Buffer buffer, Error *err)
|
void nvim_win_set_buf(Window window, Buffer buffer, Error *err)
|
||||||
FUNC_API_SINCE(5)
|
FUNC_API_SINCE(5)
|
||||||
FUNC_API_TEXTLOCK
|
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
|
||||||
{
|
{
|
||||||
win_set_buf(window, buffer, false, err);
|
win_T *win = find_window_by_handle(window, err);
|
||||||
|
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||||
|
if (!win || !buf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cmdwin_type != 0 && (win == curwin || buf == curbuf)) {
|
||||||
|
api_set_error(err, kErrorTypeException, "%s", e_cmdwin);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
win_set_buf(win, buf, false, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the (1,0)-indexed, buffer-relative cursor position for a given window
|
/// Gets the (1,0)-indexed, buffer-relative cursor position for a given window
|
||||||
@ -353,10 +362,10 @@ Boolean nvim_win_is_valid(Window window)
|
|||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
void nvim_win_hide(Window window, Error *err)
|
void nvim_win_hide(Window window, Error *err)
|
||||||
FUNC_API_SINCE(7)
|
FUNC_API_SINCE(7)
|
||||||
FUNC_API_TEXTLOCK
|
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
|
||||||
{
|
{
|
||||||
win_T *win = find_window_by_handle(window, err);
|
win_T *win = find_window_by_handle(window, err);
|
||||||
if (!win) {
|
if (!win || !can_close_in_cmdwin(win, err)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,16 +397,7 @@ void nvim_win_close(Window window, Boolean force, Error *err)
|
|||||||
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
|
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
|
||||||
{
|
{
|
||||||
win_T *win = find_window_by_handle(window, err);
|
win_T *win = find_window_by_handle(window, err);
|
||||||
if (!win) {
|
if (!win || !can_close_in_cmdwin(win, err)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmdwin_type != 0) {
|
|
||||||
if (win == curwin) {
|
|
||||||
cmdwin_result = Ctrl_C;
|
|
||||||
} else {
|
|
||||||
api_set_error(err, kErrorTypeException, "%s", _(e_cmdwin));
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1137,7 +1137,7 @@ static void recording_mode(int attr)
|
|||||||
/// of 'ru_col'.
|
/// of 'ru_col'.
|
||||||
void comp_col(void)
|
void comp_col(void)
|
||||||
{
|
{
|
||||||
int last_has_status = (p_ls > 1 || (p_ls == 1 && !ONE_WINDOW));
|
bool last_has_status = last_stl_height(false) > 0;
|
||||||
|
|
||||||
sc_col = 0;
|
sc_col = 0;
|
||||||
ru_col = 0;
|
ru_col = 0;
|
||||||
|
@ -4398,6 +4398,7 @@ static int open_cmdwin(void)
|
|||||||
// Set "cmdwin_type" before any autocommands may mess things up.
|
// Set "cmdwin_type" before any autocommands may mess things up.
|
||||||
cmdwin_type = get_cmdline_type();
|
cmdwin_type = get_cmdline_type();
|
||||||
cmdwin_level = ccline.level;
|
cmdwin_level = ccline.level;
|
||||||
|
cmdwin_old_curwin = old_curwin;
|
||||||
|
|
||||||
// Create empty command-line buffer.
|
// Create empty command-line buffer.
|
||||||
if (buf_open_scratch(0, _("[Command Line]")) == FAIL) {
|
if (buf_open_scratch(0, _("[Command Line]")) == FAIL) {
|
||||||
@ -4405,6 +4406,7 @@ static int open_cmdwin(void)
|
|||||||
win_close(curwin, true, false);
|
win_close(curwin, true, false);
|
||||||
ga_clear(&winsizes);
|
ga_clear(&winsizes);
|
||||||
cmdwin_type = 0;
|
cmdwin_type = 0;
|
||||||
|
cmdwin_old_curwin = NULL;
|
||||||
return Ctrl_C;
|
return Ctrl_C;
|
||||||
}
|
}
|
||||||
// Command-line buffer has bufhidden=wipe, unlike a true "scratch" buffer.
|
// Command-line buffer has bufhidden=wipe, unlike a true "scratch" buffer.
|
||||||
@ -4501,6 +4503,7 @@ static int open_cmdwin(void)
|
|||||||
|
|
||||||
cmdwin_type = 0;
|
cmdwin_type = 0;
|
||||||
cmdwin_level = 0;
|
cmdwin_level = 0;
|
||||||
|
cmdwin_old_curwin = NULL;
|
||||||
|
|
||||||
exmode_active = save_exmode;
|
exmode_active = save_exmode;
|
||||||
|
|
||||||
|
@ -831,6 +831,7 @@ EXTERN bool km_startsel INIT(= false);
|
|||||||
EXTERN int cmdwin_type INIT(= 0); ///< type of cmdline window or 0
|
EXTERN int cmdwin_type INIT(= 0); ///< type of cmdline window or 0
|
||||||
EXTERN int cmdwin_result INIT(= 0); ///< result of cmdline window or 0
|
EXTERN int cmdwin_result INIT(= 0); ///< result of cmdline window or 0
|
||||||
EXTERN int cmdwin_level INIT(= 0); ///< cmdline recursion level
|
EXTERN int cmdwin_level INIT(= 0); ///< cmdline recursion level
|
||||||
|
EXTERN win_T *cmdwin_old_curwin INIT(= NULL); ///< curwin before opening cmdline window or NULL
|
||||||
|
|
||||||
EXTERN char no_lines_msg[] INIT(= N_("--No lines in buffer--"));
|
EXTERN char no_lines_msg[] INIT(= N_("--No lines in buffer--"));
|
||||||
|
|
||||||
|
@ -698,15 +698,9 @@ static void cmd_with_count(char *cmd, char *bufp, size_t bufsize, int64_t Prenum
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err)
|
void win_set_buf(win_T *win, buf_T *buf, bool noautocmd, Error *err)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
win_T *win = find_window_by_handle(window, err);
|
|
||||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
|
||||||
|
|
||||||
if (!win || !buf) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tabpage_T *tab = win_find_tabpage(win);
|
tabpage_T *tab = win_find_tabpage(win);
|
||||||
|
|
||||||
// no redrawing and don't set the window title
|
// no redrawing and don't set the window title
|
||||||
@ -720,7 +714,7 @@ void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err)
|
|||||||
api_set_error(err,
|
api_set_error(err,
|
||||||
kErrorTypeException,
|
kErrorTypeException,
|
||||||
"Failed to switch to window %d",
|
"Failed to switch to window %d",
|
||||||
window);
|
win->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
try_start();
|
try_start();
|
||||||
@ -729,7 +723,7 @@ void win_set_buf(Window window, Buffer buffer, bool noautocmd, Error *err)
|
|||||||
api_set_error(err,
|
api_set_error(err,
|
||||||
kErrorTypeException,
|
kErrorTypeException,
|
||||||
"Failed to set buffer %d",
|
"Failed to set buffer %d",
|
||||||
buffer);
|
buf->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If window is not current, state logic will not validate its cursor.
|
// If window is not current, state logic will not validate its cursor.
|
||||||
@ -2676,6 +2670,23 @@ static bool can_close_floating_windows(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @return true if, considering the cmdwin, `win` is safe to close.
|
||||||
|
/// If false and `win` is the cmdwin, it is closed; otherwise, `err` is set.
|
||||||
|
bool can_close_in_cmdwin(win_T *win, Error *err)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
{
|
||||||
|
if (cmdwin_type != 0) {
|
||||||
|
if (win == curwin) {
|
||||||
|
cmdwin_result = Ctrl_C;
|
||||||
|
return false;
|
||||||
|
} else if (win == cmdwin_old_curwin) {
|
||||||
|
api_set_error(err, kErrorTypeException, "%s", e_cmdwin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// Close the possibly last window in a tab page.
|
/// Close the possibly last window in a tab page.
|
||||||
///
|
///
|
||||||
/// @param win window to close
|
/// @param win window to close
|
||||||
@ -5701,8 +5712,9 @@ void win_size_save(garray_T *gap)
|
|||||||
{
|
{
|
||||||
ga_init(gap, (int)sizeof(int), 1);
|
ga_init(gap, (int)sizeof(int), 1);
|
||||||
ga_grow(gap, win_count() * 2 + 1);
|
ga_grow(gap, win_count() * 2 + 1);
|
||||||
// first entry is value of 'lines'
|
// first entry is the total lines available for windows
|
||||||
((int *)gap->ga_data)[gap->ga_len++] = Rows;
|
((int *)gap->ga_data)[gap->ga_len++] =
|
||||||
|
(int)ROWS_AVAIL + global_stl_height() - last_stl_height(false);
|
||||||
|
|
||||||
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
|
||||||
((int *)gap->ga_data)[gap->ga_len++] =
|
((int *)gap->ga_data)[gap->ga_len++] =
|
||||||
@ -5712,13 +5724,14 @@ void win_size_save(garray_T *gap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore window sizes, but only if the number of windows is still the same
|
// Restore window sizes, but only if the number of windows is still the same
|
||||||
// and 'lines' didn't change.
|
// and total lines available for windows didn't change.
|
||||||
// Does not free the growarray.
|
// Does not free the growarray.
|
||||||
void win_size_restore(garray_T *gap)
|
void win_size_restore(garray_T *gap)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
if (win_count() * 2 + 1 == gap->ga_len
|
if (win_count() * 2 + 1 == gap->ga_len
|
||||||
&& ((int *)gap->ga_data)[0] == Rows) {
|
&& ((int *)gap->ga_data)[0] ==
|
||||||
|
(int)ROWS_AVAIL + global_stl_height() - last_stl_height(false)) {
|
||||||
// The order matters, because frames contain other frames, but it's
|
// The order matters, because frames contain other frames, but it's
|
||||||
// difficult to get right. The easy way out is to do it twice.
|
// difficult to get right. The easy way out is to do it twice.
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
@ -6982,8 +6995,7 @@ char *file_name_in_line(char *line, int col, int options, int count, char *rel_f
|
|||||||
void last_status(bool morewin)
|
void last_status(bool morewin)
|
||||||
{
|
{
|
||||||
// Don't make a difference between horizontal or vertical split.
|
// Don't make a difference between horizontal or vertical split.
|
||||||
last_status_rec(topframe, (p_ls == 2 || (p_ls == 1 && (morewin || !one_nonfloat()))),
|
last_status_rec(topframe, last_stl_height(morewin) > 0, global_stl_height() > 0);
|
||||||
global_stl_height() > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove status line from window, replacing it with a horizontal separator if needed.
|
// Remove status line from window, replacing it with a horizontal separator if needed.
|
||||||
@ -7182,6 +7194,14 @@ int global_stl_height(void)
|
|||||||
return (p_ls == 3) ? STATUS_HEIGHT : 0;
|
return (p_ls == 3) ? STATUS_HEIGHT : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the height of the last window's statusline, or the global statusline if set.
|
||||||
|
///
|
||||||
|
/// @param morewin pretend there are two or more windows if true.
|
||||||
|
int last_stl_height(bool morewin)
|
||||||
|
{
|
||||||
|
return (p_ls > 1 || (p_ls == 1 && (!one_nonfloat() || morewin))) ? STATUS_HEIGHT : 0;
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the minimal number of rows that is needed on the screen to display
|
/// Return the minimal number of rows that is needed on the screen to display
|
||||||
/// the current number of windows.
|
/// the current number of windows.
|
||||||
int min_rows(void)
|
int min_rows(void)
|
||||||
|
@ -43,6 +43,22 @@ describe('API/win', function()
|
|||||||
eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
|
eq('Invalid buffer id: 23', pcall_err(window, 'set_buf', nvim('get_current_win'), 23))
|
||||||
eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
|
eq('Invalid window id: 23', pcall_err(window, 'set_buf', 23, nvim('get_current_buf')))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('disallowed in cmdwin if win=curwin or buf=curbuf', function()
|
||||||
|
local new_buf = meths.create_buf(true, true)
|
||||||
|
local new_win = meths.open_win(new_buf, false, {
|
||||||
|
relative='editor', row=10, col=10, width=50, height=10,
|
||||||
|
})
|
||||||
|
feed('q:')
|
||||||
|
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
||||||
|
pcall_err(meths.win_set_buf, 0, new_buf))
|
||||||
|
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
||||||
|
pcall_err(meths.win_set_buf, new_win, 0))
|
||||||
|
|
||||||
|
local next_buf = meths.create_buf(true, true)
|
||||||
|
meths.win_set_buf(new_win, next_buf)
|
||||||
|
eq(next_buf, meths.win_get_buf(new_win))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('{get,set}_cursor', function()
|
describe('{get,set}_cursor', function()
|
||||||
@ -524,15 +540,21 @@ describe('API/win', function()
|
|||||||
command('split')
|
command('split')
|
||||||
eq(2, #meths.list_wins())
|
eq(2, #meths.list_wins())
|
||||||
local oldwin = meths.get_current_win()
|
local oldwin = meths.get_current_win()
|
||||||
|
local otherwin = meths.open_win(0, false, {
|
||||||
|
relative='editor', row=10, col=10, width=10, height=10,
|
||||||
|
})
|
||||||
-- Open cmdline-window.
|
-- Open cmdline-window.
|
||||||
feed('q:')
|
feed('q:')
|
||||||
eq(3, #meths.list_wins())
|
eq(4, #meths.list_wins())
|
||||||
eq(':', funcs.getcmdwintype())
|
eq(':', funcs.getcmdwintype())
|
||||||
-- Vim: not allowed to close other windows from cmdline-window.
|
-- Not allowed to close previous window from cmdline-window.
|
||||||
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
||||||
pcall_err(meths.win_close, oldwin, true))
|
pcall_err(meths.win_close, oldwin, true))
|
||||||
|
-- Closing other windows is fine.
|
||||||
|
meths.win_close(otherwin, true)
|
||||||
|
eq(false, meths.win_is_valid(otherwin))
|
||||||
-- Close cmdline-window.
|
-- Close cmdline-window.
|
||||||
meths.win_close(0,true)
|
meths.win_close(0, true)
|
||||||
eq(2, #meths.list_wins())
|
eq(2, #meths.list_wins())
|
||||||
eq('', funcs.getcmdwintype())
|
eq('', funcs.getcmdwintype())
|
||||||
end)
|
end)
|
||||||
@ -593,6 +615,24 @@ describe('API/win', function()
|
|||||||
eq({oldwin}, meths.list_wins())
|
eq({oldwin}, meths.list_wins())
|
||||||
eq({oldbuf}, meths.list_bufs())
|
eq({oldbuf}, meths.list_bufs())
|
||||||
end)
|
end)
|
||||||
|
it('in the cmdwin', function()
|
||||||
|
feed('q:')
|
||||||
|
-- Can close the cmdwin.
|
||||||
|
meths.win_hide(0)
|
||||||
|
eq('', funcs.getcmdwintype())
|
||||||
|
|
||||||
|
local old_win = meths.get_current_win()
|
||||||
|
local other_win = meths.open_win(0, false, {
|
||||||
|
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',
|
||||||
|
pcall_err(meths.win_hide, old_win))
|
||||||
|
-- Can close other windows.
|
||||||
|
meths.win_hide(other_win)
|
||||||
|
eq(false, meths.win_is_valid(other_win))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('text_height', function()
|
describe('text_height', function()
|
||||||
@ -821,6 +861,31 @@ describe('API/win', function()
|
|||||||
})
|
})
|
||||||
eq(1, funcs.exists('g:fired'))
|
eq(1, funcs.exists('g:fired'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('disallowed in cmdwin if enter=true or buf=curbuf', function()
|
||||||
|
local new_buf = meths.create_buf(true, true)
|
||||||
|
feed('q:')
|
||||||
|
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
||||||
|
pcall_err(meths.open_win, new_buf, true, {
|
||||||
|
relative='editor', row=5, col=5, width=5, height=5,
|
||||||
|
}))
|
||||||
|
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
||||||
|
pcall_err(meths.open_win, 0, false, {
|
||||||
|
relative='editor', row=5, col=5, width=5, height=5,
|
||||||
|
}))
|
||||||
|
|
||||||
|
eq(new_buf, meths.win_get_buf(meths.open_win(new_buf, false, {
|
||||||
|
relative='editor', row=5, col=5, width=5, height=5,
|
||||||
|
})))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('aborts if buffer is invalid', function()
|
||||||
|
local wins_before = meths.list_wins()
|
||||||
|
eq('Invalid buffer id: 1337', pcall_err(meths.open_win, 1337, false, {
|
||||||
|
relative='editor', row=5, col=5, width=5, height=5,
|
||||||
|
}))
|
||||||
|
eq(wins_before, meths.list_wins())
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('get_config', function()
|
describe('get_config', function()
|
||||||
|
@ -984,14 +984,46 @@ it('tabline is not redrawn in Ex mode #24122', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
describe("cmdline height", function()
|
describe("cmdline height", function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
it("does not crash resized screen #14263", function()
|
it("does not crash resized screen #14263", function()
|
||||||
clear()
|
|
||||||
local screen = Screen.new(25, 10)
|
local screen = Screen.new(25, 10)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
command('set cmdheight=9999')
|
command('set cmdheight=9999')
|
||||||
screen:try_resize(25, 5)
|
screen:try_resize(25, 5)
|
||||||
assert_alive()
|
assert_alive()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('unchanged when trying to restore window sizes', function()
|
||||||
|
command('set showtabline=0 cmdheight=2 laststatus=0')
|
||||||
|
feed('q:') -- Closing cmdwin tries to restore sizes
|
||||||
|
command('set cmdheight=1 | quit')
|
||||||
|
eq(1, eval('&cmdheight'))
|
||||||
|
|
||||||
|
command('set showtabline=2 cmdheight=3')
|
||||||
|
feed('q:')
|
||||||
|
command('set showtabline=0 | quit')
|
||||||
|
eq(3, eval('&cmdheight'))
|
||||||
|
|
||||||
|
command('set cmdheight=1 laststatus=2')
|
||||||
|
feed('q:')
|
||||||
|
command('set laststatus=0 | quit')
|
||||||
|
eq(1, eval('&cmdheight'))
|
||||||
|
|
||||||
|
command('set laststatus=2')
|
||||||
|
feed('q:')
|
||||||
|
command('set laststatus=1 | quit')
|
||||||
|
eq(1, eval('&cmdheight'))
|
||||||
|
|
||||||
|
command('set laststatus=2 | belowright vsplit | wincmd _')
|
||||||
|
local restcmds = eval('winrestcmd()')
|
||||||
|
feed('q:')
|
||||||
|
command('set laststatus=1 | quit')
|
||||||
|
-- As we have 2 windows, &ls = 1 should still have a statusline on the last
|
||||||
|
-- window. As such, the number of available rows hasn't changed and the window
|
||||||
|
-- sizes should be restored.
|
||||||
|
eq(restcmds, eval('winrestcmd()'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('cmdheight=0', function()
|
describe('cmdheight=0', function()
|
||||||
|
@ -73,9 +73,10 @@ describe('eval-API', function()
|
|||||||
|
|
||||||
-- Some functions checking textlock (usually those that may change the current window or buffer)
|
-- Some functions checking textlock (usually those that may change the current window or buffer)
|
||||||
-- also ought to not be usable in the cmdwin.
|
-- also ought to not be usable in the cmdwin.
|
||||||
|
local old_win = meths.get_current_win()
|
||||||
feed("q:")
|
feed("q:")
|
||||||
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
eq('E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
|
||||||
pcall_err(meths.win_hide, 0))
|
pcall_err(meths.set_current_win, old_win))
|
||||||
|
|
||||||
-- But others, like nvim_buf_set_lines(), which just changes text, is OK.
|
-- But others, like nvim_buf_set_lines(), which just changes text, is OK.
|
||||||
curbufmeths.set_lines(0, -1, 1, {"wow!"})
|
curbufmeths.set_lines(0, -1, 1, {"wow!"})
|
||||||
|
Loading…
Reference in New Issue
Block a user