fix(terminal): possibly wrong wrow/wcol in active terminal

Problem: w_wrow/col calculation in terminal_check_cursor is wrong when the
terminal is smaller than the window. Common when there's a larger window open
with the same terminal, or just after a resize (as refresh_size is deferred).

Solution: don't calculate it; validate_cursor will correct it later if it's
out-of-date.

Note that the toplines set for the terminal (also before this PR) assume
'nowrap' (which is set by default for terminal windows), and that no weird stuff
like filler lines are around. That means, for example, it's possible for the
cursor to be moved off-screen if there's wrapped lines. If this happens, it's
likely update_topline will move the cursor back on screen via validate_cursor or
similar, but maybe this should be handled more elegantly in the future?
This commit is contained in:
Sean Dewar
2025-08-22 13:54:05 +01:00
parent c845f1923d
commit e6ba78919c
2 changed files with 5 additions and 8 deletions

View File

@@ -832,8 +832,6 @@ bool terminal_enter(void)
static void terminal_check_cursor(void) static void terminal_check_cursor(void)
{ {
Terminal *term = curbuf->terminal; Terminal *term = curbuf->terminal;
curwin->w_wrow = term->cursor.row;
curwin->w_wcol = term->cursor.col + win_col_off(curwin);
curwin->w_cursor.lnum = MIN(curbuf->b_ml.ml_line_count, curwin->w_cursor.lnum = MIN(curbuf->b_ml.ml_line_count,
row_to_linenr(term, term->cursor.row)); row_to_linenr(term, term->cursor.row));
const linenr_T topline = MAX(curbuf->b_ml.ml_line_count - curwin->w_view_height + 1, 1); const linenr_T topline = MAX(curbuf->b_ml.ml_line_count - curwin->w_view_height + 1, 1);

View File

@@ -495,13 +495,12 @@ describe(':terminal window', function()
{1:-- TERMINAL --} | {1:-- TERMINAL --} |
]]) ]])
command('tabprevious') command('tabprevious')
-- TODO(seandewar): w_wrow's wrong if the terminal doesn't match the window size...
screen:expect([[ screen:expect([[
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
{19:r}ows: 5, cols: 25 │rows: 5, cols: 25 | {19:r}ows: 5, cols: 25 │rows: 5, cols: 25 |
rows: 5, cols: 50 │rows: 5, cols: 50 | rows: 5, cols: 50 │rows: 5, cols: 50 |
{19: } │ |
{19: } │^ | {19: } │^ |
{19: } │ |
{18:foo [-] }{17:foo [-] }| {18:foo [-] }{17:foo [-] }|
{1:-- TERMINAL --} | {1:-- TERMINAL --} |
]]) ]])
@@ -510,8 +509,8 @@ describe(':terminal window', function()
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
{19:r}ows: 5, cols: 25 │rows: 5, cols: 25 | {19:r}ows: 5, cols: 25 │rows: 5, cols: 25 |
rows: 5, cols: 50 │rows: 5, cols: 50 | rows: 5, cols: 50 │rows: 5, cols: 50 |
{19: } │{12: }| {19: } │{12:^ }|
{19: } │^ | {19: } │ |
{18:foo [-] }{17:foo [-] }| {18:foo [-] }{17:foo [-] }|
| |
]]) ]])
@@ -533,8 +532,8 @@ describe(':terminal window', function()
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
{19:r}ows: 5, cols: 25 │rows: 5, cols: 25 | {19:r}ows: 5, cols: 25 │rows: 5, cols: 25 |
rows: 5, cols: 50 │rows: 5, cols: 50 | rows: 5, cols: 50 │rows: 5, cols: 50 |
{19: } │ |
{19: } │^ | {19: } │^ |
{19: } │ |
{18:foo [-] }{17:foo [-] }| {18:foo [-] }{17:foo [-] }|
{1:-- TERMINAL --} | {1:-- TERMINAL --} |
]]) ]])
@@ -566,8 +565,8 @@ describe(':terminal window', function()
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
│rows: 5, cols: 25 | │rows: 5, cols: 25 |
{6:~ }│rows: 5, cols: 50 | {6:~ }│rows: 5, cols: 50 |
{6:~ }│ |
{6:~ }│^ | {6:~ }│^ |
{6:~ }│ |
{4:[No Name] }{17:foo [-] }| {4:[No Name] }{17:foo [-] }|
{1:-- TERMINAL --} | {1:-- TERMINAL --} |
]]) ]])