fix(inccommand): skip split window if not enough room #18937

Command preview now behaves like inccommand=nosplit when there's not
enough room for the preview window to be opened instead of aborting,
which is consistent with old behavior of 'inccommand'.
This commit is contained in:
Famiu Haque
2022-06-12 23:59:04 +06:00
committed by GitHub
parent f4967828f9
commit 2de0d67144
2 changed files with 14 additions and 13 deletions

View File

@@ -2325,19 +2325,9 @@ static buf_T *cmdpreview_open_buf(void)
static win_T *cmdpreview_open_win(buf_T *cmdpreview_buf) static win_T *cmdpreview_open_win(buf_T *cmdpreview_buf)
{ {
win_T *save_curwin = curwin; win_T *save_curwin = curwin;
bool win_found = false;
// Try to find an existing preview window. // Open preview window.
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (win_split((int)p_cwh, WSP_BOT) == FAIL) {
if (wp->w_buffer == cmdpreview_buf) {
win_enter(wp, false);
win_found = true;
break;
}
}
// If an existing window is not found, create one.
if (!win_found && win_split((int)p_cwh, WSP_BOT) == FAIL) {
return NULL; return NULL;
} }
@@ -2459,7 +2449,8 @@ static void cmdpreview_show(CommandLineState *s)
// If inccommand=split and preview callback returns 2, open preview window. // If inccommand=split and preview callback returns 2, open preview window.
if (icm_split && cmdpreview_type == 2 if (icm_split && cmdpreview_type == 2
&& (cmdpreview_win = cmdpreview_open_win(cmdpreview_buf)) == NULL) { && (cmdpreview_win = cmdpreview_open_win(cmdpreview_buf)) == NULL) {
abort(); // If there's not enough room to open the preview window, just preview without the window.
cmdpreview_type = 1;
} }
// If preview callback is nonzero, update screen now. // If preview callback is nonzero, update screen now.

View File

@@ -2051,6 +2051,16 @@ describe("'inccommand' split windows", function()
end end
end) end)
it("don't open if there's not enough room", function()
refresh()
screen:try_resize(40, 3)
feed("gg:%s/tw")
screen:expect([[
Inc substitution on |
{12:tw}o lines |
:%s/tw^ |
]])
end)
end) end)
describe("'inccommand' with 'gdefault'", function() describe("'inccommand' with 'gdefault'", function()