# HG changeset patch # User Bram Moolenaar # Date 1685903404 -7200 # Node ID 745f1e43106f2ea87ee385842c42ca4e25cc9b2a # Parent 0bd6f91ccbbaaa8eb6369d015047c8b22c59a547 patch 9.0.1607: screenpos() returns wrong row with diff filler lines Commit: https://github.com/vim/vim/commit/55daae392157823dc5434e6be1344f4336bfe96f Author: zeertzjq Date: Sun Jun 4 19:29:22 2023 +0100 patch 9.0.1607: screenpos() returns wrong row with diff filler lines Problem: screenpos() returns wrong row with diff filler lines. Solution: Only add filler lines when appropriate. Also don't add the 'smoothscroll' marker when w_skipcol is zero. (closes #12485, closes #12484) diff --git a/src/move.c b/src/move.c --- a/src/move.c +++ b/src/move.c @@ -344,7 +344,8 @@ update_topline(void) check_topline = TRUE; else if (check_top_offset()) check_topline = TRUE; - else if (curwin->w_cursor.lnum == curwin->w_topline) + else if (curwin->w_skipcol > 0 + && curwin->w_cursor.lnum == curwin->w_topline) { colnr_T vcol; @@ -1459,7 +1460,8 @@ textpos2screenpos( #ifdef FEAT_DIFF // Add filler lines above this buffer line. - row += diff_check_fill(wp, lnum); + row += lnum == wp->w_topline ? wp->w_topfill + : diff_check_fill(wp, lnum); #endif colnr_T off = win_col_off(wp); @@ -1479,7 +1481,7 @@ textpos2screenpos( col += off; width = wp->w_width - off + win_col_off2(wp); - if (pos->lnum == wp->w_topline) + if (lnum == wp->w_topline) col -= wp->w_skipcol; // long line wrapping, adjust row @@ -1848,6 +1850,7 @@ scrollup( } } + // TODO: is comparing w_topline with prev_topline still needed? if (curwin->w_topline == prev_topline || curwin->w_skipcol != prev_skipcol) // need to redraw because wl_size of the topline may now be invalid diff --git a/src/testdir/test_cursor_func.vim b/src/testdir/test_cursor_func.vim --- a/src/testdir/test_cursor_func.vim +++ b/src/testdir/test_cursor_func.vim @@ -132,13 +132,14 @@ func Test_screenpos() 1split normal G$ redraw + " w_skipcol should be subtracted call assert_equal({'row': winrow + 0, \ 'col': wincol + 20 - 1, \ 'curscol': wincol + 20 - 1, \ 'endcol': wincol + 20 - 1}, \ screenpos(win_getid(), line('.'), col('.'))) - " w_skipcol should be subtracted + " w_leftcol should be subtracted setlocal nowrap normal 050zl$ call assert_equal({'row': winrow + 0, @@ -203,6 +204,19 @@ func Test_screenpos_diff() windo diffthis wincmd w call assert_equal(#{col: 3, row: 7, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) + call assert_equal(#{col: 3, row: 8, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) + exe "normal! 3\" + call assert_equal(#{col: 3, row: 4, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) + call assert_equal(#{col: 3, row: 5, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) + exe "normal! \" + call assert_equal(#{col: 3, row: 3, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) + call assert_equal(#{col: 3, row: 4, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) + exe "normal! \" + call assert_equal(#{col: 3, row: 2, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) + call assert_equal(#{col: 3, row: 3, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) + exe "normal! \" + call assert_equal(#{col: 3, row: 1, endcol: 3, curscol: 3}, screenpos(0, 4, 1)) + call assert_equal(#{col: 3, row: 2, endcol: 3, curscol: 3}, screenpos(0, 5, 1)) windo diffoff bwipe! diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1607, +/**/ 1606, /**/ 1605,