Skip to content

Commit 8509014

Browse files
committed
patch 9.0.1597: cursor ends up below the window after a put
Problem: Cursor ends up below the window after a put. Solution: Mark w_crow and w_botline invalid when changing the cursor line. (closes #12465)
1 parent eb43b7f commit 8509014

6 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/eval.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6322,6 +6322,10 @@ var2fpos(
63226322

63236323
if (name[0] == 'w' && dollar_lnum)
63246324
{
6325+
// the "w_valid" flags are not reset when moving the cursor, but they
6326+
// do matter for update_topline() and validate_botline().
6327+
check_cursor_moved(curwin);
6328+
63256329
pos.col = 0;
63266330
if (name[1] == '0') // "w0": first visible line
63276331
{

src/move.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,19 +715,21 @@ set_topline(win_T *wp, linenr_T lnum)
715715
/*
716716
* Call this function when the length of the cursor line (in screen
717717
* characters) has changed, and the change is before the cursor.
718+
* If the line length changed the number of screen lines might change,
719+
* requiring updating w_topline. That may also invalidate w_crow.
718720
* Need to take care of w_botline separately!
719721
*/
720722
void
721723
changed_cline_bef_curs(void)
722724
{
723-
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL
725+
curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW
724726
|VALID_CHEIGHT|VALID_TOPLINE);
725727
}
726728

727729
void
728730
changed_cline_bef_curs_win(win_T *wp)
729731
{
730-
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL
732+
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW
731733
|VALID_CHEIGHT|VALID_TOPLINE);
732734
}
733735

src/register.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,7 @@ do_put(
20982098
{
20992099
// make sure curwin->w_virtcol is updated
21002100
changed_cline_bef_curs();
2101+
invalidate_botline();
21012102
curwin->w_cursor.col += (colnr_T)(totlen - 1);
21022103
}
21032104
if (VIsual_active)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|2+0&#ffffff0| @73
2+
|3| @73
3+
|4| @73
4+
|5| @73
5+
|6| @73
6+
|7| @73
7+
|8| @73
8+
|9|x@73
9+
@73>x|
10+
@57|1|0|,|1|4|9| @7|B|o|t|

src/testdir/test_put.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,23 @@ func Test_put_other_window()
262262
call StopVimInTerminal(buf)
263263
endfunc
264264

265+
func Test_put_in_last_displayed_line()
266+
CheckRunVimInTerminal
267+
268+
let lines =<< trim END
269+
vim9script
270+
autocmd CursorMoved * eval line('w$')
271+
@a = 'x'->repeat(&columns * 2 - 2)
272+
range(&lines)->setline(1)
273+
feedkeys('G"ap')
274+
END
275+
call writefile(lines, 'Xtest_put_last_line', 'D')
276+
let buf = RunVimInTerminal('-S Xtest_put_last_line', #{rows: 10})
277+
278+
call VerifyScreenDump(buf, 'Test_put_in_last_displayed_line_1', {})
279+
280+
call StopVimInTerminal(buf)
281+
endfunc
282+
265283

266284
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1597,
698700
/**/
699701
1596,
700702
/**/

0 commit comments

Comments
 (0)