Skip to content

Commit 361895d

Browse files
ychinbrammool
authored andcommitted
patch 9.0.0908: with 'smoothscroll' cursor may end up in wrong position
Problem: With 'smoothscroll' cursor may end up in wrong position. Solution: Correct the computation of screen lines. (Yee Cheng Chin, closes #11502)
1 parent d63a855 commit 361895d

15 files changed

Lines changed: 92 additions & 16 deletions

src/move.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,18 +2460,50 @@ scroll_cursor_bot(int min_scroll, int set_topbot)
24602460
used = curwin->w_cline_height;
24612461
#endif
24622462

2463-
// If the cursor is below botline, we will at least scroll by the height
2464-
// of the cursor line. Correct for empty lines, which are really part of
2465-
// botline.
2463+
// If the cursor is on or below botline, we will at least scroll by the
2464+
// height of the cursor line, which is "used". Correct for empty lines,
2465+
// which are really part of botline.
24662466
if (cln >= curwin->w_botline)
24672467
{
24682468
scrolled = used;
24692469
if (cln == curwin->w_botline)
24702470
scrolled -= curwin->w_empty_rows;
24712471
min_scrolled = scrolled;
2472-
if (cln > curwin->w_botline && curwin->w_p_sms && curwin->w_p_wrap)
2473-
for (linenr_T lnum = curwin->w_botline + 1; lnum <= cln; ++lnum)
2474-
min_scrolled += PLINES_NOFILL(lnum);
2472+
if (curwin->w_p_sms && curwin->w_p_wrap)
2473+
{
2474+
// 'smoothscroll' and 'wrap' are set
2475+
if (cln > curwin->w_botline)
2476+
// add screen lines below w_botline
2477+
for (linenr_T lnum = curwin->w_botline + 1; lnum <= cln; ++lnum)
2478+
min_scrolled += PLINES_NOFILL(lnum);
2479+
2480+
// Calculate how many screen lines the current top line of window
2481+
// occupies. If it is occupying more than the entire window, we
2482+
// need to scroll the additional clipped lines to scroll past the
2483+
// top line before we can move on to the other lines.
2484+
int top_plines =
2485+
#ifdef FEAT_DIFF
2486+
plines_win_nofill
2487+
#else
2488+
plines_win
2489+
#endif
2490+
(curwin, curwin->w_topline, FALSE);
2491+
int skip_lines = 0;
2492+
int width1 = curwin->w_width - curwin_col_off();
2493+
int width2 = width1 + curwin_col_off2();
2494+
// similar formula is used in curs_columns()
2495+
if (curwin->w_skipcol > width1)
2496+
skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
2497+
else if (curwin->w_skipcol > 0)
2498+
skip_lines = 1;
2499+
2500+
top_plines -= skip_lines;
2501+
if (top_plines > curwin->w_height)
2502+
{
2503+
scrolled += (top_plines - curwin->w_height);
2504+
min_scrolled += (top_plines - curwin->w_height);
2505+
}
2506+
}
24752507
}
24762508

24772509
/*

src/testdir/dumps/Test_smooth_long_1.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
44
|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
55
|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
6-
| @21|3|,|1|0| @9|B|o|t|
6+
| @21|3|,|1|0| @9|6@1|%|
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
>f+0&#ffffff0|o|u|r| @35
2+
|~+0#4040ff13&| @38
3+
|~| @38
4+
|~| @38
5+
|~| @38
6+
|:+0#0000000&|s|e|t| |s|c|r|o|l@1|o| @9|4|,|1| @10|B|o|t|
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|<+0#4040ff13#ffffff0@2|t+0#0000000&|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t
2+
|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
3+
|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
4+
|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |e|n|d| @11
5+
>f|o|u|r| @35
6+
@22|4|,|1| @10|B|o|t|
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
|<+0#4040ff13#ffffff0@2|t+0#0000000&|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t
2+
|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
3+
|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
4+
|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |e|n|d| @11
5+
|f|o|u>r| @35
6+
@22|4|,|4| @10|B|o|t|

src/testdir/dumps/Test_smooth_long_2.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
44
|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
55
|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w
6-
| @21|3|,|5|0| @9|B|o|t|
6+
| @21|3|,|5|0| @9|6@1|%|

src/testdir/dumps/Test_smooth_long_3.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f|
44
|t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t
55
| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t
6-
| @21|3|,|2|5|0| @8|B|o|t|
6+
| @21|3|,|2|5|0| @8|6@1|%|

src/testdir/dumps/Test_smooth_long_4.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
44
|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
55
|x|t| |w|i|t|h| |l>o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w
6-
| @21|3|,|2|1|0| @8|B|o|t|
6+
| @21|3|,|2|1|0| @8|6@1|%|

src/testdir/dumps/Test_smooth_long_5.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o
44
|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
55
|f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
6-
| @21|3|,|1|7|0| @8|B|o|t|
6+
| @21|3|,|1|7|0| @8|6@1|%|

src/testdir/dumps/Test_smooth_long_6.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o
44
|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e
55
|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w
6-
| @21|3|,|9|0| @9|B|o|t|
6+
| @21|3|,|9|0| @9|6@1|%|

0 commit comments

Comments
 (0)