astepano / rpms / vim

Forked from rpms/vim 6 years ago
Clone
37c7ade
To: vim-dev@vim.org
37c7ade
Subject: Patch 7.1.220
37c7ade
Fcc: outbox
37c7ade
From: Bram Moolenaar <Bram@moolenaar.net>
37c7ade
Mime-Version: 1.0
37c7ade
Content-Type: text/plain; charset=ISO-8859-1
37c7ade
Content-Transfer-Encoding: 8bit
37c7ade
------------
37c7ade
37c7ade
Patch 7.1.220
37c7ade
Problem:    When a ")" or word movement command moves the cursor back from the
37c7ade
	    end of the line it may end up on the trail byte of a multi-byte
37c7ade
	    character.  It's also moved back when it isn't needed.
37c7ade
Solution:   Add the adjust_cursor() function.
37c7ade
Files:	    src/normal.c
37c7ade
37c7ade
37c7ade
*** ../vim-7.1.219/src/normal.c	Sun Jan  6 20:05:36 2008
37c7ade
--- src/normal.c	Sat Jan 12 17:10:14 2008
37c7ade
***************
37c7ade
*** 150,155 ****
37c7ade
--- 150,156 ----
37c7ade
  static void	nv_bck_word __ARGS((cmdarg_T *cap));
37c7ade
  static void	nv_wordcmd __ARGS((cmdarg_T *cap));
37c7ade
  static void	nv_beginline __ARGS((cmdarg_T *cap));
37c7ade
+ static void	adjust_cursor __ARGS((oparg_T *oap));
37c7ade
  #ifdef FEAT_VISUAL
37c7ade
  static void	adjust_for_sel __ARGS((cmdarg_T *cap));
37c7ade
  static int	unadjust_for_sel __ARGS((void));
37c7ade
***************
37c7ade
*** 6567,6578 ****
37c7ade
  	clearopbeep(cap->oap);
37c7ade
      else
37c7ade
      {
37c7ade
! 	/* Don't leave the cursor on the NUL past a line */
37c7ade
! 	if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
37c7ade
! 	{
37c7ade
! 	    --curwin->w_cursor.col;
37c7ade
! 	    cap->oap->inclusive = TRUE;
37c7ade
! 	}
37c7ade
  #ifdef FEAT_VIRTUALEDIT
37c7ade
  	curwin->w_cursor.coladd = 0;
37c7ade
  #endif
37c7ade
--- 6568,6575 ----
37c7ade
  	clearopbeep(cap->oap);
37c7ade
      else
37c7ade
      {
37c7ade
! 	/* Don't leave the cursor on the NUL past end of line. */
37c7ade
! 	adjust_cursor(cap->oap);
37c7ade
  #ifdef FEAT_VIRTUALEDIT
37c7ade
  	curwin->w_cursor.coladd = 0;
37c7ade
  #endif
37c7ade
***************
37c7ade
*** 8408,8419 ****
37c7ade
      else
37c7ade
  	n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP);
37c7ade
  
37c7ade
!     /* Don't leave the cursor on the NUL past a line */
37c7ade
!     if (n != FAIL && curwin->w_cursor.col > 0 && gchar_cursor() == NUL)
37c7ade
!     {
37c7ade
! 	--curwin->w_cursor.col;
37c7ade
! 	cap->oap->inclusive = TRUE;
37c7ade
!     }
37c7ade
  
37c7ade
      if (n == FAIL && cap->oap->op_type == OP_NOP)
37c7ade
  	clearopbeep(cap->oap);
37c7ade
--- 8405,8413 ----
37c7ade
      else
37c7ade
  	n = fwd_word(cap->count1, cap->arg, cap->oap->op_type != OP_NOP);
37c7ade
  
37c7ade
!     /* Don't leave the cursor on the NUL past the end of line. */
37c7ade
!     if (n != FAIL)
37c7ade
! 	adjust_cursor(cap->oap);
37c7ade
  
37c7ade
      if (n == FAIL && cap->oap->op_type == OP_NOP)
37c7ade
  	clearopbeep(cap->oap);
37c7ade
***************
37c7ade
*** 8426,8431 ****
37c7ade
--- 8420,8458 ----
37c7ade
  	if ((fdo_flags & FDO_HOR) && KeyTyped && cap->oap->op_type == OP_NOP)
37c7ade
  	    foldOpenCursor();
37c7ade
  #endif
37c7ade
+     }
37c7ade
+ }
37c7ade
+ 
37c7ade
+ /*
37c7ade
+  * Used after a movement command: If the cursor ends up on the NUL after the
37c7ade
+  * end of the line, may move it back to the last character and make the motion
37c7ade
+  * inclusive.
37c7ade
+  */
37c7ade
+     static void
37c7ade
+ adjust_cursor(oap)
37c7ade
+     oparg_T *oap;
37c7ade
+ {
37c7ade
+     /* The cursor cannot remain on the NUL when:
37c7ade
+      * - the column is > 0
37c7ade
+      * - not in Visual mode or 'selection' is "o"
37c7ade
+      * - 'virtualedit' is not "all" and not "onemore".
37c7ade
+      */
37c7ade
+     if (curwin->w_cursor.col > 0 && gchar_cursor() == NUL
37c7ade
+ #ifdef FEAT_VISUAL
37c7ade
+ 		&& (!VIsual_active || *p_sel == 'o')
37c7ade
+ #endif
37c7ade
+ #ifdef FEAT_VIRTUALEDIT
37c7ade
+ 		&& !virtual_active() && (ve_flags & VE_ONEMORE) == 0
37c7ade
+ #endif
37c7ade
+ 		)
37c7ade
+     {
37c7ade
+ 	--curwin->w_cursor.col;
37c7ade
+ #ifdef FEAT_MBYTE
37c7ade
+ 	/* prevent cursor from moving on the trail byte */
37c7ade
+ 	if (has_mbyte)
37c7ade
+ 	    mb_adjust_cursor();
37c7ade
+ #endif
37c7ade
+ 	oap->inclusive = TRUE;
37c7ade
      }
37c7ade
  }
37c7ade
  
37c7ade
*** ../vim-7.1.219/src/version.c	Sat Jan 12 16:45:25 2008
37c7ade
--- src/version.c	Sat Jan 12 17:07:28 2008
37c7ade
***************
37c7ade
*** 668,669 ****
37c7ade
--- 668,671 ----
37c7ade
  {   /* Add new patch number below this line */
37c7ade
+ /**/
37c7ade
+     220,
37c7ade
  /**/
37c7ade
37c7ade
-- 
37c7ade
A hamburger walks into a bar, and the bartender says: "I'm sorry,
37c7ade
but we don't serve food here."
37c7ade
37c7ade
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
37c7ade
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
37c7ade
\\\        download, build and distribute -- http://www.A-A-P.org        ///
37c7ade
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///