fix(terminal): cursor moves on resize when line above is full width #40996

This commit is contained in:
Barrett Ruth
2026-07-28 13:59:18 -05:00
committed by GitHub
parent 0d36e61d70
commit 635acc7dc8
3 changed files with 51 additions and 1 deletions

View File

@@ -608,7 +608,7 @@ static void resize_buffer(VTermScreen *screen, int bufidx, int new_rows, int new
count--;
}
if (old_cursor.row == old_row && old_cursor.col >= old_col) {
if (old_row <= old_row_end && old_cursor.row == old_row && old_cursor.col >= old_col) {
new_cursor.row = new_row, new_cursor.col = (old_cursor.col - old_col + new_col);
if (new_cursor.col >= new_cols) {
new_cursor.col = new_cols - 1;

View File

@@ -16,6 +16,7 @@ local eval = n.eval
local skip = t.skip
local is_os = t.is_os
local testprg = n.testprg
local api = n.api
describe(':terminal window', function()
before_each(clear)
@@ -36,6 +37,33 @@ describe(':terminal window', function()
eq({ 1, 1, 1 }, eval('[&l:list, &list, &g:list]'))
end)
it('keeps the cursor put on resize when the line above it is full width', function()
local screen = Screen.new(50, 7)
local buf = api.nvim_create_buf(true, true)
local chan = api.nvim_open_term(buf, {})
api.nvim_win_set_buf(0, buf)
feed('i')
api.nvim_chan_send(chan, 'l1\r\nl2\r\nl3\r\nl4\r\n' .. ('A'):rep(50) .. '\r\nX')
screen:expect([[
l1 |
l2 |
l3 |
l4 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|
X^ |
{5:-- TERMINAL --} |
]])
screen:try_resize(50, 6)
screen:expect([[
l2 |
l3 |
l4 |
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA|
X^ |
{5:-- TERMINAL --} |
]])
end)
it('resets horizontal scroll on resize #35331', function()
skip(is_os('win'), 'Too flaky on Windows')
local screen = tt.setup_screen(0, { testprg('shell-test'), 'INTERACT' })

View File

@@ -3800,6 +3800,28 @@ putglyph 1f3f4,200d,2620,fe0f 2 0,4]])
push('\x1b[2;1Habc\r\n\x1b[H', vt)
resize(1, 1, vt)
cursor(0, 0, state)
reset(state, screen)
resize(4, 4, vt)
push('ABCD\r\nX', vt)
screen_row(0, 'ABCD', screen, vt.cols)
screen_row(1, 'X', screen, vt.cols)
cursor(1, 1, state)
resize(4, 5, vt)
screen_row(0, 'ABCD', screen, vt.cols)
screen_row(1, 'X', screen, vt.cols)
cursor(1, 1, state)
reset(state, screen)
resize(4, 4, vt)
push('ABCD\r\nX', vt)
cursor(1, 1, state)
resize(3, 4, vt)
screen_row(0, 'ABCD', screen, vt.cols)
screen_row(1, 'X', screen, vt.cols)
cursor(1, 1, state)
resize(5, 10, vt)
end)
pending('90vttest_01-movement-1', function() end)