neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit e56292071a4bc73755fc2670247bdabe64f3506c
parent 302e59f734ec4d2e032b32e0134f6925c73d1f10
Author: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Date:   Thu,  8 May 2025 18:50:47 +0100

fix(terminal): check size when switching buffers

Problem: terminal not always resized when switching to its buffer.
Solution: add missing calls to terminal_check_size.

Diffstat:
Msrc/nvim/buffer.c | 4++++
Msrc/nvim/ex_cmds.c | 3+++
Mtest/functional/terminal/buffer_spec.lua | 21+++++++++++++++++++++
3 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c @@ -1773,6 +1773,10 @@ void enter_buffer(buf_T *buf) } curbuf->b_last_used = time(NULL); + if (curbuf->terminal != NULL) { + terminal_check_size(curbuf->terminal); + } + redraw_later(curwin, UPD_NOT_VALID); } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c @@ -2743,6 +2743,9 @@ theend: if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->terminal != NULL) { terminal_check_size(old_curbuf.br_buf->terminal); } + if ((!bufref_valid(&old_curbuf) || curbuf != old_curbuf.br_buf) && curbuf->terminal != NULL) { + terminal_check_size(curbuf->terminal); + } if (did_inc_redrawing_disabled) { RedrawingDisabled--; diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua @@ -322,6 +322,27 @@ describe(':terminal buffer', function() eq({ mode = 'nt', blocking = false }, api.nvim_get_mode()) command('bd!') end) + + it('correct size when switching buffers', function() + local term_buf = api.nvim_get_current_buf() + command('file foo | enew | vsplit') + api.nvim_set_current_buf(term_buf) + screen:expect([[ + tty ready │ | + ^rows: 5, cols: 25 │{4:~ }| + │{4:~ }|*3 + {17:foo [-] }{1:[No Name] }| + | + ]]) + + feed('<C-^><C-W><C-O><C-^>') + screen:expect([[ + tty ready | + ^rows: 5, cols: 25 | + rows: 6, cols: 50 | + |*4 + ]]) + end) end) describe(':terminal buffer', function()