Patch 8.2.2385

5 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 21, 2021, 11:12:16 AM1/21/21
to vim...@googlegroups.com

Patch 8.2.2385
Problem: "gj" and "gk" do not work correctly when inside a fold.
Solution: Move check for folding. (closes #7724, closes #4095)
Files: src/normal.c, src/testdir/test_fold.vim


*** ../vim-8.2.2384/src/normal.c 2021-01-16 20:20:59.646487092 +0100
--- src/normal.c 2021-01-21 16:58:17.807717313 +0100
***************
*** 2570,2581 ****
else
{
// to previous line
- if (curwin->w_cursor.lnum == 1)
- {
- retval = FAIL;
- break;
- }
- --curwin->w_cursor.lnum;
#ifdef FEAT_FOLDING
// Move to the start of a closed fold. Don't do that when
// 'foldopen' contains "all": it will open in a moment.
--- 2570,2575 ----
***************
*** 2583,2588 ****
--- 2577,2589 ----
(void)hasFolding(curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL);
#endif
+ if (curwin->w_cursor.lnum == 1)
+ {
+ retval = FAIL;
+ break;
+ }
+ --curwin->w_cursor.lnum;
+
linelen = linetabsize(ml_get_curline());
if (linelen > width1)
curwin->w_curswant += (((linelen - width1 - 1) / width2)
***************
*** 5957,5969 ****
*/
case 'j':
case K_DOWN:
! // with 'nowrap' it works just like the normal "j" command; also when
! // in a closed fold
! if (!curwin->w_p_wrap
! #ifdef FEAT_FOLDING
! || hasFolding(curwin->w_cursor.lnum, NULL, NULL)
! #endif
! )
{
oap->motion_type = MLINE;
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
--- 5958,5965 ----
*/
case 'j':
case K_DOWN:
! // with 'nowrap' it works just like the normal "j" command.
! if (!curwin->w_p_wrap)
{
oap->motion_type = MLINE;
i = cursor_down(cap->count1, oap->op_type == OP_NOP);
***************
*** 5976,5988 ****

case 'k':
case K_UP:
! // with 'nowrap' it works just like the normal "k" command; also when
! // in a closed fold
! if (!curwin->w_p_wrap
! #ifdef FEAT_FOLDING
! || hasFolding(curwin->w_cursor.lnum, NULL, NULL)
! #endif
! )
{
oap->motion_type = MLINE;
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
--- 5972,5979 ----

case 'k':
case K_UP:
! // with 'nowrap' it works just like the normal "k" command.
! if (!curwin->w_p_wrap)
{
oap->motion_type = MLINE;
i = cursor_up(cap->count1, oap->op_type == OP_NOP);
*** ../vim-8.2.2384/src/testdir/test_fold.vim 2020-12-21 14:01:38.328550550 +0100
--- src/testdir/test_fold.vim 2021-01-21 17:01:00.123366585 +0100
***************
*** 859,862 ****
--- 859,897 ----
bwipe!
endfunc

+ func Test_fold_relative_move()
+ enew!
+ set fdm=indent sw=2 wrap tw=80
+
+ let content = [ ' foo', ' bar', ' baz',
+ \ repeat('x', 100),
+ \ ' foo', ' bar', ' baz'
+ \ ]
+ call append(0, content)
+
+ normal zM
+
+ call cursor(3, 1)
+ call assert_true(foldclosed(line('.')))
+ normal gj
+ call assert_equal(2, winline())
+
+ call cursor(2, 1)
+ call assert_true(foldclosed(line('.')))
+ normal 2gj
+ call assert_equal(3, winline())
+
+ call cursor(5, 1)
+ call assert_true(foldclosed(line('.')))
+ normal gk
+ call assert_equal(3, winline())
+
+ call cursor(6, 1)
+ call assert_true(foldclosed(line('.')))
+ normal 2gk
+ call assert_equal(2, winline())
+
+ set fdm& sw& wrap& tw&
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.2384/src/version.c 2021-01-21 14:45:08.914738378 +0100
--- src/version.c 2021-01-21 17:02:49.451237190 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2385,
/**/

--
hundred-and-one symptoms of being an internet addict:
199. You read this entire list of symptoms, looking for something
that doesn't describe you.

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