Patch 9.0.0900

4 views
Skip to first unread message

Bram Moolenaar

unread,
Nov 18, 2022, 7:53:46 AM11/18/22
to vim...@googlegroups.com

Patch 9.0.0900
Problem: Cursor moves too far with 'smoothscroll'.
Solution: Only move as far as really needed. (Yee Cheng Chin, closes #11504)
Files: src/move.c, src/testdir/test_scroll_opt.vim,
src/testdir/dumps/Test_smooth_long_showbreak_2.dump,
src/testdir/dumps/Test_smooth_number_7.dump,
src/testdir/dumps/Test_smooth_wrap_5.dump,
src/testdir/dumps/Test_smooth_wrap_6.dump


*** ../vim-9.0.0899/src/move.c 2022-11-17 12:41:38.350199459 +0000
--- src/move.c 2022-11-18 12:39:21.782920740 +0000
***************
*** 202,207 ****
--- 202,227 ----
#endif

/*
+ * Calculates how much overlap the smoothscroll marker "<<<" overlaps with
+ * buffer text for curwin.
+ * Parameter "extra2" should be the padding on the 2nd line, not the first
+ * line.
+ * Returns the number of columns of overlap with buffer text, excluding the
+ * extra padding on the ledge.
+ */
+ static int
+ smoothscroll_marker_overlap(int extra2)
+ {
+ #if defined(FEAT_LINEBREAK)
+ // We don't draw the <<< marker when in showbreak mode, thus no need to
+ // account for it. See wlv_screen_line().
+ if (*get_showbreak_value(curwin) != NUL)
+ return 0;
+ #endif
+ return extra2 > 3 ? 0 : 3 - extra2;
+ }
+
+ /*
* Set curwin->s_skipcol to zero and redraw later if needed.
*/
static void
***************
*** 311,320 ****
{
colnr_T vcol;

! // check the cursor position is visible. Add 3 for the ">>>"
! // displayed in the top-left.
getvvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
! if (curwin->w_skipcol + 3 >= vcol)
check_topline = TRUE;
}
}
--- 331,343 ----
{
colnr_T vcol;

! // Check that the cursor position is visible. Add columns for
! // the smoothscroll marker "<<<" displayed in the top-left if
! // needed.
getvvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
! int smoothscroll_overlap = smoothscroll_marker_overlap(
! curwin_col_off() - curwin_col_off2());
! if (curwin->w_skipcol + smoothscroll_overlap > vcol)
check_topline = TRUE;
}
}
***************
*** 1811,1835 ****
if (curwin->w_cursor.lnum == curwin->w_topline
&& do_sms && curwin->w_skipcol > 0)
{
! int width1 = curwin->w_width - curwin_col_off();
! int width2 = width1 + curwin_col_off2();
long so = get_scrolloff_value();
int scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
int space_cols = (curwin->w_height - 1) * width2;

// Make sure the cursor is in a visible part of the line, taking
// 'scrolloff' into account, but using screen lines.
// If there are not enough screen lines put the cursor in the middle.
if (scrolloff_cols > space_cols / 2)
scrolloff_cols = space_cols / 2;
validate_virtcol();
! if (curwin->w_virtcol < curwin->w_skipcol + 3 + scrolloff_cols)
{
colnr_T col = curwin->w_virtcol;

if (col < width1)
col += width1;
! while (col < curwin->w_skipcol + 3 + scrolloff_cols)
col += width2;
curwin->w_curswant = col;
coladvance(curwin->w_curswant);
--- 1834,1869 ----
if (curwin->w_cursor.lnum == curwin->w_topline
&& do_sms && curwin->w_skipcol > 0)
{
! int col_off = curwin_col_off();
! int col_off2 = curwin_col_off2();
!
! int width1 = curwin->w_width - col_off;
! int width2 = width1 + col_off2;
! int extra2 = col_off - col_off2;
long so = get_scrolloff_value();
int scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
int space_cols = (curwin->w_height - 1) * width2;

+ // If we have non-zero scrolloff, just ignore the <<< marker as we are
+ // going past it anyway.
+ int smoothscroll_overlap = scrolloff_cols != 0 ? 0 :
+ smoothscroll_marker_overlap(extra2);
+
// Make sure the cursor is in a visible part of the line, taking
// 'scrolloff' into account, but using screen lines.
// If there are not enough screen lines put the cursor in the middle.
if (scrolloff_cols > space_cols / 2)
scrolloff_cols = space_cols / 2;
validate_virtcol();
! if (curwin->w_virtcol < curwin->w_skipcol
! + smoothscroll_overlap + scrolloff_cols)
{
colnr_T col = curwin->w_virtcol;

if (col < width1)
col += width1;
! while (col < curwin->w_skipcol
! + smoothscroll_overlap + scrolloff_cols)
col += width2;
curwin->w_curswant = col;
coladvance(curwin->w_curswant);
***************
*** 2818,2826 ****
static void get_scroll_overlap(lineoff_T *lp, int dir);

/*
! * move screen 'count' pages up or down and update screen
*
! * return FAIL for failure, OK otherwise
*/
int
onepage(int dir, long count)
--- 2852,2860 ----
static void get_scroll_overlap(lineoff_T *lp, int dir);

/*
! * Move screen "count" pages up or down and update screen.
*
! * Return FAIL for failure, OK otherwise.
*/
int
onepage(int dir, long count)
*** ../vim-9.0.0899/src/testdir/test_scroll_opt.vim 2022-11-17 18:59:49.275178378 +0000
--- src/testdir/test_scroll_opt.vim 2022-11-18 12:30:37.763549083 +0000
***************
*** 230,239 ****
call term_sendkeys(buf, "G")
call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})

! " moving cursor up - whole top line shows
! call term_sendkeys(buf, "2k")
call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})

call StopVimInTerminal(buf)
endfunc

--- 230,243 ----
call term_sendkeys(buf, "G")
call VerifyScreenDump(buf, 'Test_smooth_wrap_4', {})

! " moving cursor up right after the >>> marker - no need to show whole line
! call term_sendkeys(buf, "2gj3l2k")
call VerifyScreenDump(buf, 'Test_smooth_wrap_5', {})

+ " moving cursor up where the >>> marker is - whole top line shows
+ call term_sendkeys(buf, "2j02k")
+ call VerifyScreenDump(buf, 'Test_smooth_wrap_6', {})
+
call StopVimInTerminal(buf)
endfunc

***************
*** 321,327 ****
let buf = RunVimInTerminal('-S XSmoothLongShowbreak', #{rows: 6, cols: 40})
call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_1', {})

- " FIXME: this currently has the cursor in screen line 2, should be one up.
call term_sendkeys(buf, "\<C-E>")
call VerifyScreenDump(buf, 'Test_smooth_long_showbreak_2', {})

--- 325,330 ----
***************
*** 353,362 ****
call s:check_col_calc(1, 2, 41)
exe "normal \<C-Y>"
call s:check_col_calc(1, 3, 41)
! normal ggg$
exe "normal \<C-E>"

" Move down only 1 line when we are out of the range of the <<< display
call s:check_col_calc(20, 1, 40)
exe "normal \<C-Y>"
call s:check_col_calc(20, 2, 40)
--- 356,371 ----
call s:check_col_calc(1, 2, 41)
exe "normal \<C-Y>"
call s:check_col_calc(1, 3, 41)
!
! normal gg3l
exe "normal \<C-E>"

" Move down only 1 line when we are out of the range of the <<< display
+ call s:check_col_calc(4, 1, 24)
+ exe "normal \<C-Y>"
+ call s:check_col_calc(4, 2, 24)
+ normal ggg$
+ exe "normal \<C-E>"
call s:check_col_calc(20, 1, 40)
exe "normal \<C-Y>"
call s:check_col_calc(20, 2, 40)
***************
*** 366,374 ****
setl number
call s:check_col_calc(5, 1, 1)
exe "normal \<C-E>"
! call s:check_col_calc(5, 2, 33)
exe "normal \<C-Y>"
! call s:check_col_calc(5, 3, 33)
normal ggg$
exe "normal \<C-E>"
call s:check_col_calc(20, 1, 32)
--- 375,385 ----
setl number
call s:check_col_calc(5, 1, 1)
exe "normal \<C-E>"
!
! " Move down only 1 line when the <<< display is on the number column
! call s:check_col_calc(5, 1, 17)
exe "normal \<C-Y>"
! call s:check_col_calc(5, 2, 17)
normal ggg$
exe "normal \<C-E>"
call s:check_col_calc(20, 1, 32)
***************
*** 376,388 ****
call s:check_col_calc(20, 2, 32)
normal gg

" Test number + showbreak, so test that the additional indentation works
setl number showbreak=+++
call s:check_col_calc(5, 1, 1)
exe "normal \<C-E>"
! call s:check_col_calc(8, 2, 30)
exe "normal \<C-Y>"
! call s:check_col_calc(8, 3, 30)
normal gg

" Test number + cpo+=n mode, where wrapped lines aren't indented
--- 387,419 ----
call s:check_col_calc(20, 2, 32)
normal gg

+ setl numberwidth=1
+
+ " Move down another line when numberwidth is too short to cover the whole
+ " <<< display
+ call s:check_col_calc(3, 1, 1)
+ exe "normal \<C-E>"
+ call s:check_col_calc(3, 2, 37)
+ exe "normal \<C-Y>"
+ call s:check_col_calc(3, 3, 37)
+ normal ggl
+
+ " Only move 1 line down when we are just past the <<< display
+ call s:check_col_calc(4, 1, 2)
+ exe "normal \<C-E>"
+ call s:check_col_calc(4, 1, 20)
+ exe "normal \<C-Y>"
+ call s:check_col_calc(4, 2, 20)
+ normal gg
+ setl numberwidth&
+
" Test number + showbreak, so test that the additional indentation works
setl number showbreak=+++
call s:check_col_calc(5, 1, 1)
exe "normal \<C-E>"
! call s:check_col_calc(8, 1, 17)
exe "normal \<C-Y>"
! call s:check_col_calc(8, 2, 17)
normal gg

" Test number + cpo+=n mode, where wrapped lines aren't indented
*** ../vim-9.0.0899/src/testdir/dumps/Test_smooth_long_showbreak_2.dump 2022-11-17 18:59:49.275178378 +0000
--- src/testdir/dumps/Test_smooth_long_showbreak_2.dump 2022-11-18 12:30:37.763549083 +0000
***************
*** 1,6 ****
! |++0#4040ff13#ffffff0@2| |o+0#0000000&|f| |t|e|x|t| |i|n| |o|n|e| |l|i|n|e| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x
! |++0#4040ff13&@2| >t+0#0000000&| |i|n| |o|n|e| |l|i|n|e| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |i|n| |o
|++0#4040ff13&@2| |n+0#0000000&|e| |l|i|n|e| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |i|n| |o|n|e| |l|i|n
|++0#4040ff13&@2| |e+0#0000000&| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |i|n| |o|n|e| |l|i|n|e| @4
|~+0#4040ff13&| @38
! | +0#0000000&@21|1|,|7@1|-|8|5| @6|A|l@1|
--- 1,6 ----
! |++0#4040ff13#ffffff0@2| >o+0#0000000&|f| |t|e|x|t| |i|n| |o|n|e| |l|i|n|e| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x
! |++0#4040ff13&@2| |t+0#0000000&| |i|n| |o|n|e| |l|i|n|e| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |i|n| |o
|++0#4040ff13&@2| |n+0#0000000&|e| |l|i|n|e| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |i|n| |o|n|e| |l|i|n
|++0#4040ff13&@2| |e+0#0000000&| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |i|n| |o|n|e| |l|i|n|e| @4
|~+0#4040ff13&| @38
! | +0#0000000&@21|1|,|4|1|-|4|5| @6|A|l@1|
*** ../vim-9.0.0899/src/testdir/dumps/Test_smooth_number_7.dump 2022-11-17 12:41:38.350199459 +0000
--- src/testdir/dumps/Test_smooth_number_7.dump 2022-11-18 12:30:37.763549083 +0000
***************
*** 1,5 ****
! |2+0#af5f00255#ffffff0|<+0#4040ff13&@2|o+0#0000000&|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e
! | +0#af5f00255&@3>x+0#0000000&|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r
| +0#af5f00255&@3|y+0#0000000&| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g
| +0#af5f00255&@3| +0#0000000&|t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t|
| +0#af5f00255&@1|1| |t+0#0000000&|h|r|e@1| @30
--- 1,5 ----
! |2+0#af5f00255#ffffff0|<+0#4040ff13&@2>o+0#0000000&|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e
! | +0#af5f00255&@3|x+0#0000000&|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r
| +0#af5f00255&@3|y+0#0000000&| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g
| +0#af5f00255&@3| +0#0000000&|t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t| |v|e|r|y| |l|o|n|g| |t|e|x|t|
| +0#af5f00255&@1|1| |t+0#0000000&|h|r|e@1| @30
***************
*** 9,12 ****
|~| @38
|~| @38
|~| @38
! |-+0#0000000&@1|N|o|.@2|e|r|-@1| @10|2|,|7|3| @9|B|o|t|
--- 9,12 ----
|~| @38
|~| @38
|~| @38
! |-+0#0000000&@1|N|o|.@2|e|r|-@1| @10|2|,|3|7| @9|B|o|t|
*** ../vim-9.0.0899/src/testdir/dumps/Test_smooth_wrap_5.dump 2022-10-06 15:46:27.932240365 +0100
--- src/testdir/dumps/Test_smooth_wrap_5.dump 2022-11-18 12:30:37.763549083 +0000
***************
*** 1,8 ****
! >L+0&#ffffff0|i|n|e| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h|
|s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t|
|w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| @10
|L|i|n|e| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h|
|s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t|
|w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| @10
! |@+0#4040ff13&@2| @36
! | +0#0000000&@21|5|,|1| @10|8|0|%|
--- 1,8 ----
! |<+0#4040ff13#ffffff0@2>h+0#0000000&| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| @10
! |L|i|n|e| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h|
|s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t|
|w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| @10
|L|i|n|e| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h|
|s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t|
|w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| @10
! @22|5|,|8|4| @9|B|o|t|
*** ../vim-9.0.0899/src/testdir/dumps/Test_smooth_wrap_6.dump 2022-11-18 12:44:41.946732287 +0000
--- src/testdir/dumps/Test_smooth_wrap_6.dump 2022-11-18 12:30:37.763549083 +0000
***************
*** 0 ****
--- 1,8 ----
+ >L+0&#ffffff0|i|n|e| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h|
+ |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t|
+ |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| @10
+ |L|i|n|e| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h|
+ |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t|
+ |w|i|t|h| |s|o|m|e| |t|e|x|t| |w|i|t|h| |s|o|m|e| |t|e|x|t| @10
+ |@+0#4040ff13&@2| @36
+ | +0#0000000&@21|5|,|1| @10|8|0|%|
*** ../vim-9.0.0899/src/version.c 2022-11-17 22:05:08.602034256 +0000
--- src/version.c 2022-11-18 12:32:55.719324801 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 900,
/**/

--
% cat /usr/include/real_life.h
void life(void);

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages