diff options
-rw-r--r-- | src/nvim/window.c | 18 | ||||
-rw-r--r-- | test/functional/ui/float_spec.lua | 232 |
2 files changed, 242 insertions, 8 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index f9a0839702..8355f5397f 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -2313,10 +2313,10 @@ int win_close(win_T *win, bool free_buf) if (!win->w_floating) { wp = frame2win(win_altframe(win, NULL)); } else { - if (win_valid(prevwin)) { + if (win_valid(prevwin) && prevwin != win) { wp = prevwin; } else { - wp = curtab->tp_firstwin; + wp = firstwin; } } @@ -2462,7 +2462,7 @@ int win_close(win_T *win, bool free_buf) } if (!was_floating) { - if (p_ea && (*p_ead == 'b' || *p_ead == dir)) { + if (!curwin->w_floating && p_ea && (*p_ead == 'b' || *p_ead == dir)) { // If the frame of the closed window contains the new current window, // only resize that frame. Otherwise resize all windows. win_equal(curwin, curwin->w_frame->fr_parent == win_frame, dir); @@ -2595,10 +2595,10 @@ win_free_mem ( wp = winframe_remove(win, dirp, tp); xfree(frp); } else { - if (win_valid(prevwin)) { + if (win_valid(prevwin) && prevwin != win) { wp = prevwin; } else { - wp = curtab->tp_firstwin; + wp = firstwin; } } win_free(win, tp); @@ -4656,8 +4656,12 @@ void win_size_restore(garray_T *gap) { int i = 0; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - frame_setwidth(wp->w_frame, ((int *)gap->ga_data)[i++]); - win_setheight_win(((int *)gap->ga_data)[i++], wp); + int width = ((int *)gap->ga_data)[i++]; + int height = ((int *)gap->ga_data)[i++]; + if (!wp->w_floating) { + frame_setwidth(wp->w_frame, width); + win_setheight_win(height, wp); + } } } /* recompute the window positions */ diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 4477573cff..4a89345ee5 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -5,6 +5,7 @@ local clear, feed = helpers.clear, helpers.feed local command, feed_command = helpers.command, helpers.feed_command local eval = helpers.eval local eq = helpers.eq +local insert = helpers.insert local meths = helpers.meths local curbufmeths = helpers.curbufmeths local funcs = helpers.funcs @@ -33,6 +34,7 @@ describe('floating windows', function() [14] = {foreground = Screen.colors.Brown}, [15] = {background = Screen.colors.Grey20}, [16] = {background = Screen.colors.Grey20, bold = true, foreground = Screen.colors.Blue1}, + [17] = {background = Screen.colors.Yellow}, } local function with_ext_multigrid(multigrid) @@ -1106,6 +1108,122 @@ describe('floating windows', function() end end) + it('does not crash with inccommand #9379', function() + local expected_pos = { + [3]={{id=1001}, 'NW', 1, 2, 0, true}, + } + + command("set inccommand=split") + command("set laststatus=2") + + local buf = meths.create_buf(false,false) + meths.open_win(buf, true, {relative='editor', width=30, height=3, row=2, col=0}) + + insert([[ + foo + bar + ]]) + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] }| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:foo }| + {1:bar }| + {1:^ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {1:foo }{0: }| + {1:bar }{0: }| + {1:^ }{0: }| + {5:[No Name] }| + | + ]]) + end + + feed(':%s/.') + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[Preview] }| + :%s/.^ | + ## grid 2 + | + ## grid 3 + {17:f}{1:oo }| + {17:b}{1:ar }| + {1: }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {5:[No Name] }| + {17:f}{1:oo } | + {17:b}{1:ar } | + {1: }{0: }| + {5:[Preview] }| + :%s/.^ | + ]]) + end + + feed('<Esc>') + + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] }| + | + ## grid 2 + | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:foo }| + {1:bar }| + {1:^ }| + ]], float_pos=expected_pos} + else + screen:expect([[ + | + {0:~ }| + {1:foo }{0: }| + {1:bar }{0: }| + {1:^ }{0: }| + {5:[No Name] }| + | + ]]) + end + end) + it('does not crash when set cmdheight #9680', function() local buf = meths.create_buf(false,false) meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) @@ -2681,6 +2799,119 @@ describe('floating windows', function() eq(exited, true) end) + it(':quit two floats in a row', function() + -- enter first float + feed('<c-w><c-w>') + -- enter second float + meths.open_win(0, true, {relative='editor', width=20, height=2, row=4, col=8}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + | + ## grid 2 + x | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:y }| + {2:~ }| + ## grid 4 + {1:^y }| + {2:~ }| + ]], float_pos={ + [3] = {{id = 1001}, "NW", 1, 2, 5, true}, + [4] = {{id = 1002}, "NW", 1, 4, 8, true} + }} + else + screen:expect([[ + x | + {0:~ }| + {0:~ }{1:y }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }{1:^y }{0: }| + {0:~ }{2:~ }{0: }| + | + ]]) + end + + feed(':quit<cr>') + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + {5:[No Name] [+] }| + :quit | + ## grid 2 + x | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 3 + {1:^y }| + {2:~ }| + ]], float_pos={ + [3] = {{id = 1001}, "NW", 1, 2, 5, true}, + }} + else + screen:expect([[ + x | + {0:~ }| + {0:~ }{1:^y }{0: }| + {0:~ }{2:~ }{0: }| + {0:~ }| + {5:[No Name] [+] }| + :quit | + ]]) + end + + feed(':quit<cr>') + if multigrid then + screen:expect([[ + ## grid 1 + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + [2:----------------------------------------]| + :quit | + ## grid 2 + ^x | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + ]]) + else + screen:expect([[ + ^x | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + :quit | + ]]) + end + + eq(2, eval('1+1')) + end) + it("o (:only) non-float", function() feed("<c-w>o") if multigrid then @@ -3343,6 +3574,5 @@ describe('floating windows', function() describe('without ext_multigrid', function() with_ext_multigrid(false) end) - end) |