Skip to content

Commit e6ba789

Browse files
committed
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?
1 parent c845f19 commit e6ba789

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/nvim/terminal.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,6 @@ bool terminal_enter(void)
832832
static void terminal_check_cursor(void)
833833
{
834834
Terminal *term = curbuf->terminal;
835-
curwin->w_wrow = term->cursor.row;
836-
curwin->w_wcol = term->cursor.col + win_col_off(curwin);
837835
curwin->w_cursor.lnum = MIN(curbuf->b_ml.ml_line_count,
838836
row_to_linenr(term, term->cursor.row));
839837
const linenr_T topline = MAX(curbuf->b_ml.ml_line_count - curwin->w_view_height + 1, 1);

test/functional/terminal/window_spec.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,12 @@ describe(':terminal window', function()
495495
{1:-- TERMINAL --} |
496496
]])
497497
command('tabprevious')
498-
-- TODO(seandewar): w_wrow's wrong if the terminal doesn't match the window size...
499498
screen:expect([[
500499
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
501500
{19:r}ows: 5, cols: 25 │rows: 5, cols: 25 |
502501
rows: 5, cols: 50 │rows: 5, cols: 50 |
503-
{19: } │ |
504502
{19: } │^ |
503+
{19: } │ |
505504
{18:foo [-] }{17:foo [-] }|
506505
{1:-- TERMINAL --} |
507506
]])
@@ -510,8 +509,8 @@ describe(':terminal window', function()
510509
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
511510
{19:r}ows: 5, cols: 25 │rows: 5, cols: 25 |
512511
rows: 5, cols: 50 │rows: 5, cols: 50 |
513-
{19: } │{12: }|
514-
{19: } │^ |
512+
{19: } │{12:^ }|
513+
{19: } │ |
515514
{18:foo [-] }{17:foo [-] }|
516515
|
517516
]])
@@ -533,8 +532,8 @@ describe(':terminal window', function()
533532
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
534533
{19:r}ows: 5, cols: 25 │rows: 5, cols: 25 |
535534
rows: 5, cols: 50 │rows: 5, cols: 50 |
536-
{19: } │ |
537535
{19: } │^ |
536+
{19: } │ |
538537
{18:foo [-] }{17:foo [-] }|
539538
{1:-- TERMINAL --} |
540539
]])
@@ -566,8 +565,8 @@ describe(':terminal window', function()
566565
{1: }{5:2}{1: foo }{2: foo }{4: }{2:X}|
567566
│rows: 5, cols: 25 |
568567
{6:~ }│rows: 5, cols: 50 |
569-
{6:~ }│ |
570568
{6:~ }│^ |
569+
{6:~ }│ |
571570
{4:[No Name] }{17:foo [-] }|
572571
{1:-- TERMINAL --} |
573572
]])

0 commit comments

Comments
 (0)