Patch 8.1.2140
Problem:    "gk" and "gj" do not work correctly in number column.
Solution:   Allow for a negative "curswant". (Zach Wegner, closes #4969)
Files:      src/testdir/test_normal.vim, src/misc2.c, src/normal.c


*** ../vim-8.1.2139/src/testdir/test_normal.vim 2019-09-24 22:47:42.578098633 
+0200
--- src/testdir/test_normal.vim 2019-10-12 16:00:01.759345020 +0200
***************
*** 2654,2657 ****
--- 2654,2682 ----
    call assert_equal(95, virtcol('.'))
    bw!
    bw!
+ 
+   " needs 80 column new window
+   new
+   vert 80new
+   set number
+   set numberwidth=10
+   set cpoptions+=n
+   put =[repeat('0',90), repeat('1',90)]
+   norm! 075l
+   call assert_equal(76, col('.'))
+   norm! gk
+   call assert_equal(1, col('.'))
+   norm! gk
+   call assert_equal(76, col('.'))
+   norm! gk
+   call assert_equal(1, col('.'))
+   norm! gj
+   call assert_equal(76, col('.'))
+   norm! gj
+   call assert_equal(1, col('.'))
+   norm! gj
+   call assert_equal(76, col('.'))
+   bw!
+   bw!
+   set cpoptions& number& numberwidth&
  endfunc
*** ../vim-8.1.2139/src/misc2.c 2019-09-28 15:51:33.818357228 +0200
--- src/misc2.c 2019-10-12 15:57:06.400003966 +0200
***************
*** 119,128 ****
      static int
  coladvance2(
      pos_T     *pos,
!     int               addspaces,      /* change the text to achieve our goal? 
*/
!     int               finetune,       /* change char offset for the exact 
column */
!     colnr_T   wcol)           /* column to move to */
  {
      int               idx;
      char_u    *ptr;
      char_u    *line;
--- 119,129 ----
      static int
  coladvance2(
      pos_T     *pos,
!     int               addspaces,      // change the text to achieve our goal?
!     int               finetune,       // change char offset for the exact 
column
!     colnr_T   wcol_arg)       // column to move to (can be negative)
  {
+     colnr_T   wcol = wcol_arg;
      int               idx;
      char_u    *ptr;
      char_u    *line;
***************
*** 136,142 ****
      one_more = (State & INSERT)
                    || restart_edit != NUL
                    || (VIsual_active && *p_sel != 'o')
!                   || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL) ;
      line = ml_get_buf(curbuf, pos->lnum, FALSE);
  
      if (wcol >= MAXCOL)
--- 137,143 ----
      one_more = (State & INSERT)
                    || restart_edit != NUL
                    || (VIsual_active && *p_sel != 'o')
!                   || ((ve_flags & VE_ONEMORE) && wcol < MAXCOL);
      line = ml_get_buf(curbuf, pos->lnum, FALSE);
  
      if (wcol >= MAXCOL)
***************
*** 206,211 ****
--- 207,213 ----
  
        if (virtual_active()
                && addspaces
+               && wcol >= 0
                && ((col != wcol && col != wcol + 1) || csize > 1))
        {
            /* 'virtualedit' is set: The difference between wcol and col is
***************
*** 305,311 ****
      if (has_mbyte)
        mb_adjustpos(curbuf, pos);
  
!     if (col < wcol)
        return FAIL;
      return OK;
  }
--- 307,313 ----
      if (has_mbyte)
        mb_adjustpos(curbuf, pos);
  
!     if (wcol < 0 || col < wcol)
        return FAIL;
      return OK;
  }
*** ../vim-8.1.2139/src/normal.c        2019-09-30 23:12:10.874289153 +0200
--- src/normal.c        2019-10-12 15:59:32.791449044 +0200
***************
*** 2499,2515 ****
            n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
        else
            n = width1;
!       if (curwin->w_curswant > (colnr_T)n + 1)
!           curwin->w_curswant -= ((curwin->w_curswant - n) / width2 + 1)
!                                                                    * width2;
        }
  
        while (dist--)
        {
        if (dir == BACKWARD)
        {
!           if ((long)curwin->w_curswant > width2)
!               // move back within line
                curwin->w_curswant -= width2;
            else
            {
--- 2499,2516 ----
            n = ((linelen - width1 - 1) / width2 + 1) * width2 + width1;
        else
            n = width1;
!       if (curwin->w_curswant >= (colnr_T)n)
!           curwin->w_curswant = n - 1;
        }
  
        while (dist--)
        {
        if (dir == BACKWARD)
        {
!           if ((long)curwin->w_curswant >= width1)
!               // Move back within the line. This can give a negative value
!               // for w_curswant if width1 < width2 (with cpoptions+=n),
!               // which will get clipped to column 0.
                curwin->w_curswant -= width2;
            else
            {
***************
*** 2557,2562 ****
--- 2558,2569 ----
                }
                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
+               // to get a negative value for w_curswant, which will get
+               // clipped to column 0.
+               if (curwin->w_curswant >= width1)
+                   curwin->w_curswant -= width2;
                linelen = linetabsize(ml_get_curline());
            }
        }
*** ../vim-8.1.2139/src/version.c       2019-10-12 15:36:06.236897202 +0200
--- src/version.c       2019-10-12 16:00:34.915225464 +0200
***************
*** 755,756 ****
--- 755,758 ----
  {   /* Add new patch number below this line */
+ /**/
+     2140,
  /**/

-- 
You can be stopped by the police for biking over 65 miles per hour.
You are not allowed to walk across a street on your hands.
                [real standing laws in Connecticut, United States of America]

 /// Bram Moolenaar -- [email protected] -- 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    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201910121413.x9CEDOIZ018419%40masaka.moolenaar.net.

Raspunde prin e-mail lui