Skip to content

Commit d86e279

Browse files
famiukraftwerk28
authored andcommitted
fix(inccommand): skip split window if not enough room neovim#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'.
1 parent 4d64e4c commit d86e279

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/nvim/ex_getln.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,19 +2325,9 @@ static buf_T *cmdpreview_open_buf(void)
23252325
static win_T *cmdpreview_open_win(buf_T *cmdpreview_buf)
23262326
{
23272327
win_T *save_curwin = curwin;
2328-
bool win_found = false;
23292328

2330-
// Try to find an existing preview window.
2331-
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
2332-
if (wp->w_buffer == cmdpreview_buf) {
2333-
win_enter(wp, false);
2334-
win_found = true;
2335-
break;
2336-
}
2337-
}
2338-
2339-
// If an existing window is not found, create one.
2340-
if (!win_found && win_split((int)p_cwh, WSP_BOT) == FAIL) {
2329+
// Open preview window.
2330+
if (win_split((int)p_cwh, WSP_BOT) == FAIL) {
23412331
return NULL;
23422332
}
23432333

@@ -2459,7 +2449,8 @@ static void cmdpreview_show(CommandLineState *s)
24592449
// If inccommand=split and preview callback returns 2, open preview window.
24602450
if (icm_split && cmdpreview_type == 2
24612451
&& (cmdpreview_win = cmdpreview_open_win(cmdpreview_buf)) == NULL) {
2462-
abort();
2452+
// If there's not enough room to open the preview window, just preview without the window.
2453+
cmdpreview_type = 1;
24632454
}
24642455

24652456
// If preview callback is nonzero, update screen now.

test/functional/ui/inccommand_spec.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,16 @@ describe("'inccommand' split windows", function()
20512051
end
20522052
end)
20532053

2054+
it("don't open if there's not enough room", function()
2055+
refresh()
2056+
screen:try_resize(40, 3)
2057+
feed("gg:%s/tw")
2058+
screen:expect([[
2059+
Inc substitution on |
2060+
{12:tw}o lines |
2061+
:%s/tw^ |
2062+
]])
2063+
end)
20542064
end)
20552065

20562066
describe("'inccommand' with 'gdefault'", function()

0 commit comments

Comments
 (0)