Patch 9.0.0893

4 views
Skip to first unread message

Bram Moolenaar

unread,
Nov 17, 2022, 7:42:29 AM11/17/22
to vim...@googlegroups.com

Patch 9.0.0893
Problem: 'smoothscroll' cursor calculations wrong when 'number' is set.
Solution: Correct the code that computes the width. (closes #11492)
Files: src/move.c, src/testdir/test_scroll_opt.vim,
src/testdir/dumps/Test_smooth_number_7.dump


*** ../vim-9.0.0892/src/move.c 2022-11-17 11:34:33.329726353 +0000
--- src/move.c 2022-11-17 12:37:07.798523349 +0000
***************
*** 1127,1139 ****
&& curwin->w_skipcol > 0
&& curwin->w_wcol >= curwin->w_skipcol)
{
! // w_skipcol excludes win_col_off(). Include it here, since w_wcol
! // counts actual screen columns.
if (curwin->w_skipcol <= width1)
! curwin->w_wcol -= curwin->w_width;
else
! curwin->w_wcol -= curwin->w_width
* (((curwin->w_skipcol - width1) / width2) + 1);
did_sub_skipcol = TRUE;
}

--- 1127,1141 ----
&& curwin->w_skipcol > 0
&& curwin->w_wcol >= curwin->w_skipcol)
{
! // Deduct by multiples of width2. This allows the long line
! // wrapping formula below to correctly calculate the w_wcol value
! // when wrapping.
if (curwin->w_skipcol <= width1)
! curwin->w_wcol -= width2;
else
! curwin->w_wcol -= width2
* (((curwin->w_skipcol - width1) / width2) + 1);
+
did_sub_skipcol = TRUE;
}

*** ../vim-9.0.0892/src/testdir/test_scroll_opt.vim 2022-10-15 14:02:59.494610784 +0100
--- src/testdir/test_scroll_opt.vim 2022-11-17 12:39:23.358355632 +0000
***************
*** 308,312 ****
--- 308,378 ----
call StopVimInTerminal(buf)
endfunc

+ " Test that if the current cursor is on a smooth scrolled line, we correctly
+ " reposition it. Also check that we don't miscalculate the values by checking
+ " the consistency between wincol() and col('.') as they are calculated
+ " separately in code.
+ func Test_smoothscroll_cursor_position()
+ call NewWindow(10, 20)
+ setl smoothscroll wrap
+ call setline(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
+
+ func s:check_col_calc(win_col, win_line, buf_col)
+ call assert_equal(a:win_col, wincol())
+ call assert_equal(a:win_line, winline())
+ call assert_equal(a:buf_col, col('.'))
+ endfunc
+
+ call s:check_col_calc(1, 1, 1)
+ exe "normal \<C-E>"
+
+ " Move down another line to avoid blocking the <<< display
+ 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)
+ normal gg
+
+ " Test number, where we have indented lines
+ 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)
+ exe "normal \<C-Y>"
+ 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
+ setl number cpo+=n showbreak=
+ call s:check_col_calc(5, 1, 1)
+ exe "normal \<C-E>"
+ call s:check_col_calc(1, 2, 37)
+ exe "normal \<C-Y>"
+ call s:check_col_calc(1, 3, 37)
+ normal gg
+
+ bwipeout!
+ endfunc
+

" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-9.0.0892/src/testdir/dumps/Test_smooth_number_7.dump 2022-10-15 13:41:55.268850667 +0100
--- src/testdir/dumps/Test_smooth_number_7.dump 2022-11-17 12:33:20.006839234 +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
*** ../vim-9.0.0892/src/version.c 2022-11-17 11:34:33.333726348 +0000
--- src/version.c 2022-11-17 12:35:57.554615562 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 893,
/**/

--
From "know your smileys":
!-| I-am-a-Cylon-Centurian-with-one-red-eye-bouncing-back-and-forth

/// 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