]> granicus.if.org Git - vim/commitdiff
patch 9.0.1324: "gj" and "gk" do not move correctly over a closed fold v9.0.1324
authorLuuk van Baal <luukvbaal@gmail.com>
Sat, 18 Feb 2023 20:15:44 +0000 (20:15 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 18 Feb 2023 20:15:44 +0000 (20:15 +0000)
Problem:    "gj" and "gk" do not move correctly over a closed fold.
Solution:   Use the same code as used for "j"/"k" to go to the next/previous
            line. (Luuk van Baal, closes #12007)

src/normal.c
src/testdir/test_fold.vim
src/version.c

index f5a85ac447c80c3762829e93b5b68ee63786f046..1ab159922cb73ec8978c593efca1a71316e56621 100644 (file)
@@ -2344,20 +2344,11 @@ nv_screengo(oparg_T *oap, int dir, long dist)
            else
            {
                // to previous line
-#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.
-               if (!(fdo_flags & FDO_ALL))
-                   (void)hasFolding(curwin->w_cursor.lnum,
-                                               &curwin->w_cursor.lnum, NULL);
-#endif
-               if (curwin->w_cursor.lnum == 1)
+               if (!cursor_up_inner(curwin, 1))
                {
                    retval = FAIL;
                    break;
                }
-               --curwin->w_cursor.lnum;
-
                linelen = linetabsize_str(ml_get_curline());
                if (linelen > width1)
                    curwin->w_curswant += (((linelen - width1 - 1) / width2)
@@ -2380,17 +2371,11 @@ nv_screengo(oparg_T *oap, int dir, long dist)
            else
            {
                // to next line
-#ifdef FEAT_FOLDING
-               // Move to the end of a closed fold.
-               (void)hasFolding(curwin->w_cursor.lnum, NULL,
-                                                     &curwin->w_cursor.lnum);
-#endif
-               if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)
+               if (!cursor_down_inner(curwin, 1))
                {
                    retval = FAIL;
                    break;
                }
-               curwin->w_cursor.lnum++;
                curwin->w_curswant %= width2;
                // Check if the cursor has moved below the number display
                // when width1 < width2 (with cpoptions+=n). Subtract width2
index a35ea1e3b8a3f0828b1beee70ab28464ca2171b3..e0119c4975e9dda79c49ddb63f4a8dbadf2f99cf 100644 (file)
@@ -1748,4 +1748,11 @@ func Test_expand_fold_at_bottom_of_buffer()
   bwipe!
 endfunc
 
+func Test_fold_screenrow_motion()
+  call setline(1, repeat(['aaaa'], 5))
+  1,4fold
+  norm Ggkzo
+  call assert_equal(1, line('.'))
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index e6ccb9242e73b7b679cecabd322408f8137f2c6a..8be5a6e6480117a75957be973a40fef742a5cb5b 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1324,
 /**/
     1323,
 /**/