Skip to content

Commit 24b62ec

Browse files
luukvbaalbrammool
authored andcommitted
patch 9.0.1551: position of marker for 'smoothscroll' not computed correctly
Problem: Position of marker for 'smoothscroll' not computed correctly. Solution: Take 'list' and other options into account. (Luuk van Baal, closes vim#12393)
1 parent 81f277f commit 24b62ec

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

src/change.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ changed_common(
568568
&& wp->w_topline < lnume
569569
&& win_linetabsize(wp, wp->w_topline,
570570
ml_get(wp->w_topline), (colnr_T)MAXCOL)
571-
<= wp->w_skipcol + (wp->w_p_list
572-
&& wp->w_lcs_chars.prec ? 1 : 3))))
571+
<= wp->w_skipcol + sms_marker_overlap(wp,
572+
win_col_off(wp) - win_col_off2(wp)))))
573573
wp->w_skipcol = 0;
574574

575575
// Check if a change in the buffer has invalidated the cached

src/move.c

+22-19
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,26 @@ redraw_for_cursorcolumn(win_T *wp)
202202
#endif
203203

204204
/*
205-
* Calculates how much overlap the smoothscroll marker "<<<" overlaps with
206-
* buffer text for curwin.
205+
* Calculates how much the 'listchars' "precedes" or 'smoothscroll' "<<<"
206+
* marker overlaps with buffer text for window "wp".
207207
* Parameter "extra2" should be the padding on the 2nd line, not the first
208208
* line.
209209
* Returns the number of columns of overlap with buffer text, excluding the
210210
* extra padding on the ledge.
211211
*/
212-
static int
213-
smoothscroll_marker_overlap(int extra2)
212+
int
213+
sms_marker_overlap(win_T *wp, int extra2)
214214
{
215215
#if defined(FEAT_LINEBREAK)
216-
// We don't draw the <<< marker when in showbreak mode, thus no need to
216+
// There is no marker overlap when in showbreak mode, thus no need to
217217
// account for it. See wlv_screen_line().
218-
if (*get_showbreak_value(curwin) != NUL)
218+
if (*get_showbreak_value(wp) != NUL)
219219
return 0;
220220
#endif
221+
// Overlap when 'list' and 'listchars' "precedes" are set is 1.
222+
if (wp->w_p_list && wp->w_lcs_chars.prec)
223+
return 1;
224+
221225
return extra2 > 3 ? 0 : 3 - extra2;
222226
}
223227

@@ -346,12 +350,11 @@ update_topline(void)
346350
colnr_T vcol;
347351

348352
// Check that the cursor position is visible. Add columns for
349-
// the smoothscroll marker "<<<" displayed in the top-left if
350-
// needed.
353+
// the marker displayed in the top-left if needed.
351354
getvvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
352-
int smoothscroll_overlap = smoothscroll_marker_overlap(
353-
curwin_col_off() - curwin_col_off2());
354-
if (curwin->w_skipcol + smoothscroll_overlap > vcol)
355+
int overlap = sms_marker_overlap(curwin, curwin_col_off()
356+
- curwin_col_off2());
357+
if (curwin->w_skipcol + overlap > vcol)
355358
check_topline = TRUE;
356359
}
357360
}
@@ -1883,26 +1886,24 @@ scrollup(
18831886
int scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
18841887
int space_cols = (curwin->w_height - 1) * width2;
18851888

1886-
// If we have non-zero scrolloff, just ignore the <<< marker as we are
1889+
// If we have non-zero scrolloff, just ignore the marker as we are
18871890
// going past it anyway.
1888-
int smoothscroll_overlap = scrolloff_cols != 0 ? 0 :
1889-
smoothscroll_marker_overlap(extra2);
1891+
int overlap = scrolloff_cols != 0 ? 0
1892+
: sms_marker_overlap(curwin, extra2);
18901893

18911894
// Make sure the cursor is in a visible part of the line, taking
18921895
// 'scrolloff' into account, but using screen lines.
18931896
// If there are not enough screen lines put the cursor in the middle.
18941897
if (scrolloff_cols > space_cols / 2)
18951898
scrolloff_cols = space_cols / 2;
18961899
validate_virtcol();
1897-
if (curwin->w_virtcol < curwin->w_skipcol
1898-
+ smoothscroll_overlap + scrolloff_cols)
1900+
if (curwin->w_virtcol < curwin->w_skipcol + overlap + scrolloff_cols)
18991901
{
19001902
colnr_T col = curwin->w_virtcol;
19011903

19021904
if (col < width1)
19031905
col += width1;
1904-
while (col < curwin->w_skipcol
1905-
+ smoothscroll_overlap + scrolloff_cols)
1906+
while (col < curwin->w_skipcol + overlap + scrolloff_cols)
19061907
col += width2;
19071908
curwin->w_curswant = col;
19081909
coladvance(curwin->w_curswant);
@@ -1949,8 +1950,10 @@ adjust_skipcol(void)
19491950
}
19501951

19511952
validate_virtcol();
1953+
int overlap = sms_marker_overlap(curwin,
1954+
curwin_col_off() - curwin_col_off2());
19521955
while (curwin->w_skipcol > 0
1953-
&& curwin->w_virtcol < curwin->w_skipcol + 3 + scrolloff_cols)
1956+
&& curwin->w_virtcol < curwin->w_skipcol + overlap + scrolloff_cols)
19541957
{
19551958
// scroll a screen line down
19561959
if (curwin->w_skipcol >= width1 + width2)

src/proto/move.pro

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* move.c */
22
int adjust_plines_for_skipcol(win_T *wp, int n);
33
void redraw_for_cursorline(win_T *wp);
4+
int sms_marker_overlap(win_T *wp, int extra2);
45
void update_topline_redraw(void);
56
void update_topline(void);
67
void update_curswant_force(void);

src/testdir/test_scroll_opt.vim

+11-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,7 @@ func Test_smoothscroll_cursor_position()
426426

427427
" Test moving the cursor behind the <<< display with 'virtualedit'
428428
set virtualedit=all
429-
exe "normal \<C-E>"
430-
norm 3lgkh
429+
exe "normal \<C-E>3lgkh"
431430
call s:check_col_calc(3, 2, 23)
432431
set virtualedit&
433432

@@ -499,6 +498,16 @@ func Test_smoothscroll_cursor_position()
499498
call s:check_col_calc(1, 3, 37)
500499
normal gg
501500

501+
" Test list + listchars "precedes", where there is always 1 overlap
502+
" regardless of number and cpo-=n.
503+
setl number list listchars=precedes:< cpo-=n
504+
call s:check_col_calc(5, 1, 1)
505+
exe "normal 2|\<C-E>"
506+
call s:check_col_calc(6, 1, 18)
507+
norm h
508+
call s:check_col_calc(5, 2, 17)
509+
normal gg
510+
502511
bwipe!
503512
endfunc
504513

src/version.c

+2
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+
1551,
698700
/**/
699701
1550,
700702
/**/

0 commit comments

Comments
 (0)