diff --git a/src/nvim/window.c b/src/nvim/window.c index 7d9bf04609..f05cfca385 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -3039,6 +3039,9 @@ int win_close(win_T *win, bool free_buf, bool force) win_fix_scroll(false); } } + if (bufref.br_buf && bufref_valid(&bufref) && bufref.br_buf->terminal) { + terminal_check_size(bufref.br_buf->terminal); + } if (close_curwin) { win_enter_ext(wp, WEE_CURWIN_INVALID | WEE_TRIGGER_ENTER_AUTOCMDS @@ -3264,6 +3267,9 @@ bool win_close_othertab(win_T *win, int free_buf, tabpage_T *tp, bool force) int dir; win_free_mem(win, &dir, tp); + if (bufref.br_buf && bufref_valid(&bufref) && bufref.br_buf->terminal) { + terminal_check_size(bufref.br_buf->terminal); + } if (free_tp_idx > 0) { free_tabpage(tp); diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 7e36543cd1..d948d32cc8 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -424,9 +424,11 @@ describe(':terminal window', function() ]]) end) - it('in new tabpage has correct terminal size', function() + it('updates terminal size', function() + skip(is_os('win'), "Windows doesn't show all lines?") screen:set_default_attr_ids({ [1] = { reverse = true }, + [2] = { background = 225, foreground = Screen.colors.Gray0 }, [3] = { bold = true }, [17] = { background = 2, foreground = Screen.colors.Grey0 }, [18] = { background = 2, foreground = 8 }, @@ -453,6 +455,68 @@ describe(':terminal window', function() | {3:-- TERMINAL --} | ]]) + + command('quit | botright split') + -- NOTE: right window's cursor not on the last line, so it's not tailing. + screen:expect([[ + rows: 5, cols: 50 │rows: 5, cols: 25 | + rows: 2, cols: 50 │rows: 5, cols: 50 | + {18:foo [-] foo [-] }| + rows: 2, cols: 50 | + ^ | + {17:foo [-] }| + {3:-- TERMINAL --} | + ]]) + command('quit') + screen:expect([[ + rows: 5, cols: 25 │tty ready | + rows: 5, cols: 50 │rows: 5, cols: 25 | + rows: 2, cols: 50 │rows: 5, cols: 50 | + rows: 5, cols: 25 │rows: 2, cols: 50 | + ^ │rows: 5, cols: 25 | + {17:foo [-] }{18:foo [-] }| + {3:-- TERMINAL --} | + ]]) + command('call nvim_open_win(0, 0, #{relative: "editor", row: 0, col: 0, width: 40, height: 3})') + screen:expect([[ + {2:rows: 5, cols: 25 } | + {2:rows: 5, cols: 40 } 25 | + {2: } 50 | + rows: 5, cols: 40 │rows: 2, cols: 50 | + ^ │rows: 5, cols: 25 | + {17:foo [-] }{18:foo [-] }| + {3:-- TERMINAL --} | + ]]) + command('fclose!') + screen:expect([[ + rows: 2, cols: 50 │tty ready | + rows: 5, cols: 25 │rows: 5, cols: 25 | + rows: 5, cols: 40 │rows: 5, cols: 50 | + rows: 5, cols: 25 │rows: 2, cols: 50 | + ^ │rows: 5, cols: 25 | + {17:foo [-] }{18:foo [-] }| + {3:-- TERMINAL --} | + ]]) + command('tab split') + screen:expect([[ + {19: }{20:2}{19: foo }{3: foo }{1: }{19:X}| + rows: 5, cols: 25 | + rows: 5, cols: 40 | + rows: 5, cols: 25 | + rows: 5, cols: 50 | + ^ | + {3:-- TERMINAL --} | + ]]) + command('tabfirst | tabonly') + screen:expect([[ + rows: 5, cols: 40 │tty ready | + rows: 5, cols: 25 │rows: 5, cols: 25 | + rows: 5, cols: 50 │rows: 5, cols: 50 | + rows: 5, cols: 25 │rows: 2, cols: 50 | + ^ │rows: 5, cols: 25 | + {17:foo [-] }{18:foo [-] }| + {3:-- TERMINAL --} | + ]]) end) it('restores window options when switching terminals', function()