From d07cbb2f4225238c345d2f858c9d3e8060fbc995 Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Mon, 3 Mar 2025 14:19:32 +0000 Subject: [PATCH] fix(terminal): check size when creating new tabpage Problem: when creating a new tabpage with a terminal window, terminal size is not updated if there is no statusline. Solution: do not rely on last_status to implicitly call terminal_check_size as a side effect of making room for a statusline; call it directly. --- src/nvim/window.c | 4 +++ test/functional/terminal/window_spec.lua | 32 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/nvim/window.c b/src/nvim/window.c index 4afa695939..f432115032 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4279,6 +4279,10 @@ int win_new_tabpage(int after, char *filename) newtp->tp_topframe = topframe; last_status(false); + if (curbuf->terminal) { + terminal_check_size(curbuf->terminal); + } + redraw_all_later(UPD_NOT_VALID); tabpage_check_windows(old_curtab); diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index dfe7cbd9d8..f0b2dc1cbb 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -1,5 +1,6 @@ local t = require('test.testutil') local n = require('test.functional.testnvim')() +local Screen = require('test.functional.ui.screen') local tt = require('test.functional.testterm') local feed_data = tt.feed_data @@ -383,6 +384,37 @@ describe(':terminal window', function() ]]) end) + it('in new tabpage has correct terminal size', function() + screen:set_default_attr_ids({ + [1] = { reverse = true }, + [3] = { bold = true }, + [17] = { background = 2, foreground = Screen.colors.Grey0 }, + [18] = { background = 2, foreground = 8 }, + [19] = { underline = true, foreground = Screen.colors.Grey0, background = 7 }, + [20] = { underline = true, foreground = 5, background = 7 }, + }) + + command('file foo | vsplit') + screen:expect([[ + tty ready │tty ready | + rows: 5, cols: 25 │rows: 5, cols: 25 | + ^ │ | + │ |*2 + {17:foo [-] }{18:foo [-] }| + {3:-- TERMINAL --} | + ]]) + command('tab split') + screen:expect([[ + {19: }{20:2}{19: foo }{3: foo }{1: }{19:X}| + tty ready | + rows: 5, cols: 25 | + rows: 5, cols: 50 | + ^ | + | + {3:-- TERMINAL --} | + ]]) + end) + it('not unnecessarily redrawn by events', function() eq('t', eval('mode()')) exec_lua(function()