Skip to content

Commit 55daae3

Browse files
zeertzjqbrammool
authored andcommitted
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)
1 parent 58e1e01 commit 55daae3

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/move.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ update_topline(void)
344344
check_topline = TRUE;
345345
else if (check_top_offset())
346346
check_topline = TRUE;
347-
else if (curwin->w_cursor.lnum == curwin->w_topline)
347+
else if (curwin->w_skipcol > 0
348+
&& curwin->w_cursor.lnum == curwin->w_topline)
348349
{
349350
colnr_T vcol;
350351

@@ -1459,7 +1460,8 @@ textpos2screenpos(
14591460

14601461
#ifdef FEAT_DIFF
14611462
// Add filler lines above this buffer line.
1462-
row += diff_check_fill(wp, lnum);
1463+
row += lnum == wp->w_topline ? wp->w_topfill
1464+
: diff_check_fill(wp, lnum);
14631465
#endif
14641466

14651467
colnr_T off = win_col_off(wp);
@@ -1479,7 +1481,7 @@ textpos2screenpos(
14791481
col += off;
14801482
width = wp->w_width - off + win_col_off2(wp);
14811483

1482-
if (pos->lnum == wp->w_topline)
1484+
if (lnum == wp->w_topline)
14831485
col -= wp->w_skipcol;
14841486

14851487
// long line wrapping, adjust row
@@ -1848,6 +1850,7 @@ scrollup(
18481850
}
18491851
}
18501852

1853+
// TODO: is comparing w_topline with prev_topline still needed?
18511854
if (curwin->w_topline == prev_topline
18521855
|| curwin->w_skipcol != prev_skipcol)
18531856
// need to redraw because wl_size of the topline may now be invalid

src/testdir/test_cursor_func.vim

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ func Test_screenpos()
132132
1split
133133
normal G$
134134
redraw
135+
" w_skipcol should be subtracted
135136
call assert_equal({'row': winrow + 0,
136137
\ 'col': wincol + 20 - 1,
137138
\ 'curscol': wincol + 20 - 1,
138139
\ 'endcol': wincol + 20 - 1},
139140
\ screenpos(win_getid(), line('.'), col('.')))
140141

141-
" w_skipcol should be subtracted
142+
" w_leftcol should be subtracted
142143
setlocal nowrap
143144
normal 050zl$
144145
call assert_equal({'row': winrow + 0,
@@ -203,6 +204,19 @@ func Test_screenpos_diff()
203204
windo diffthis
204205
wincmd w
205206
call assert_equal(#{col: 3, row: 7, endcol: 3, curscol: 3}, screenpos(0, 4, 1))
207+
call assert_equal(#{col: 3, row: 8, endcol: 3, curscol: 3}, screenpos(0, 5, 1))
208+
exe "normal! 3\<C-E>"
209+
call assert_equal(#{col: 3, row: 4, endcol: 3, curscol: 3}, screenpos(0, 4, 1))
210+
call assert_equal(#{col: 3, row: 5, endcol: 3, curscol: 3}, screenpos(0, 5, 1))
211+
exe "normal! \<C-E>"
212+
call assert_equal(#{col: 3, row: 3, endcol: 3, curscol: 3}, screenpos(0, 4, 1))
213+
call assert_equal(#{col: 3, row: 4, endcol: 3, curscol: 3}, screenpos(0, 5, 1))
214+
exe "normal! \<C-E>"
215+
call assert_equal(#{col: 3, row: 2, endcol: 3, curscol: 3}, screenpos(0, 4, 1))
216+
call assert_equal(#{col: 3, row: 3, endcol: 3, curscol: 3}, screenpos(0, 5, 1))
217+
exe "normal! \<C-E>"
218+
call assert_equal(#{col: 3, row: 1, endcol: 3, curscol: 3}, screenpos(0, 4, 1))
219+
call assert_equal(#{col: 3, row: 2, endcol: 3, curscol: 3}, screenpos(0, 5, 1))
206220

207221
windo diffoff
208222
bwipe!

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+
1607,
698700
/**/
699701
1606,
700702
/**/

0 commit comments

Comments
 (0)