neovim

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

commit e6ba78919c223bd8871825edaebfa7dc92a62bf6
parent c845f1923d0f0a3f69606de4987d4e2d95856922
Author: Sean Dewar <6256228+seandewar@users.noreply.github.com>
Date:   Fri, 22 Aug 2025 13:54:05 +0100

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?

Diffstat:
Msrc/nvim/terminal.c | 2--
Mtest/functional/terminal/window_spec.lua | 11+++++------
2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c @@ -832,8 +832,6 @@ bool terminal_enter(void) static void terminal_check_cursor(void) { 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, row_to_linenr(term, term->cursor.row)); const linenr_T topline = MAX(curbuf->b_ml.ml_line_count - curwin->w_view_height + 1, 1); diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua @@ -495,13 +495,12 @@ describe(':terminal window', function() {1:-- TERMINAL --} | ]]) command('tabprevious') - -- TODO(seandewar): w_wrow's wrong if the terminal doesn't match the window size... screen:expect([[ {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| {19:r}ows: 5, cols: 25 │rows: 5, cols: 25 | rows: 5, cols: 50 │rows: 5, cols: 50 | - {19: } │ | {19: } │^ | + {19: } │ | {18:foo [-] }{17:foo [-] }| {1:-- TERMINAL --} | ]]) @@ -510,8 +509,8 @@ describe(':terminal window', function() {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| {19:r}ows: 5, cols: 25 │rows: 5, cols: 25 | rows: 5, cols: 50 │rows: 5, cols: 50 | - {19: } │{12: }| - {19: } │^ | + {19: } │{12:^ }| + {19: } │ | {18:foo [-] }{17:foo [-] }| | ]]) @@ -533,8 +532,8 @@ describe(':terminal window', function() {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| {19:r}ows: 5, cols: 25 │rows: 5, cols: 25 | rows: 5, cols: 50 │rows: 5, cols: 50 | - {19: } │ | {19: } │^ | + {19: } │ | {18:foo [-] }{17:foo [-] }| {1:-- TERMINAL --} | ]]) @@ -566,8 +565,8 @@ describe(':terminal window', function() {1: }{5:2}{1: foo }{2: foo }{4: }{2:X}| │rows: 5, cols: 25 | {6:~ }│rows: 5, cols: 50 | - {6:~ }│ | {6:~ }│^ | + {6:~ }│ | {4:[No Name] }{17:foo [-] }| {1:-- TERMINAL --} | ]])