992f13f
To: vim_dev@googlegroups.com
992f13f
Subject: Patch 7.4.186
992f13f
Fcc: outbox
992f13f
From: Bram Moolenaar <Bram@moolenaar.net>
992f13f
Mime-Version: 1.0
992f13f
Content-Type: text/plain; charset=UTF-8
992f13f
Content-Transfer-Encoding: 8bit
992f13f
------------
992f13f
992f13f
Patch 7.4.186 (after 7.4.085)
992f13f
Problem:    Insert in Visual mode sometimes gives incorrect results.
992f13f
            (Dominique Pelle)
992f13f
Solution:   Remember the original insert start position. (Christian Brabandt,
992f13f
            Dominique Pelle)
992f13f
Files:      src/edit.c, src/globals.h, src/ops.c, src/structs.h
992f13f
992f13f
992f13f
*** ../vim-7.4.185/src/edit.c	2014-01-23 22:45:54.608127182 +0100
992f13f
--- src/edit.c	2014-02-22 22:43:52.820903112 +0100
992f13f
***************
992f13f
*** 264,269 ****
992f13f
--- 264,270 ----
992f13f
  
992f13f
  static colnr_T	Insstart_textlen;	/* length of line when insert started */
992f13f
  static colnr_T	Insstart_blank_vcol;	/* vcol for first inserted blank */
992f13f
+ static int	update_Insstart_orig = TRUE; /* set Insstart_orig to Insstart */
992f13f
  
992f13f
  static char_u	*last_insert = NULL;	/* the text of the previous insert,
992f13f
  					   K_SPECIAL and CSI are escaped */
992f13f
***************
992f13f
*** 340,345 ****
992f13f
--- 341,349 ----
992f13f
       * error message */
992f13f
      check_for_delay(TRUE);
992f13f
  
992f13f
+     /* set Insstart_orig to Insstart */
992f13f
+     update_Insstart_orig = TRUE;
992f13f
+ 
992f13f
  #ifdef HAVE_SANDBOX
992f13f
      /* Don't allow inserting in the sandbox. */
992f13f
      if (sandbox != 0)
992f13f
***************
992f13f
*** 631,636 ****
992f13f
--- 635,643 ----
992f13f
  	if (arrow_used)	    /* don't repeat insert when arrow key used */
992f13f
  	    count = 0;
992f13f
  
992f13f
+ 	if (update_Insstart_orig)
992f13f
+ 	    Insstart_orig = Insstart;
992f13f
+ 
992f13f
  	if (stop_insert_mode)
992f13f
  	{
992f13f
  	    /* ":stopinsert" used or 'insertmode' reset */
992f13f
***************
992f13f
*** 6923,6928 ****
992f13f
--- 6930,6936 ----
992f13f
      if (end_insert_pos != NULL)
992f13f
      {
992f13f
  	curbuf->b_op_start = Insstart;
992f13f
+ 	curbuf->b_op_start_orig = Insstart_orig;
992f13f
  	curbuf->b_op_end = *end_insert_pos;
992f13f
      }
992f13f
  }
992f13f
***************
992f13f
*** 8257,8262 ****
992f13f
--- 8265,8271 ----
992f13f
  
992f13f
  		  /* Need to reset Insstart, esp. because a BS that joins
992f13f
  		   * a line to the previous one must save for undo. */
992f13f
+ 		  update_Insstart_orig = FALSE;
992f13f
  		  Insstart = curwin->w_cursor;
992f13f
  		  break;
992f13f
  
992f13f
*** ../vim-7.4.185/src/globals.h	2014-02-11 15:10:38.130111835 +0100
992f13f
--- src/globals.h	2014-02-22 23:02:01.644901378 +0100
992f13f
***************
992f13f
*** 752,757 ****
992f13f
--- 752,763 ----
992f13f
   */
992f13f
  EXTERN pos_T	Insstart;		/* This is where the latest
992f13f
  					 * insert/append mode started. */
992f13f
+ 
992f13f
+ /* This is where the latest insert/append mode started. In contrast to
992f13f
+  * Insstart, this won't be reset by certain keys and is needed for
992f13f
+  * op_insert(), to detect correctly where inserting by the user started. */
992f13f
+ EXTERN pos_T	Insstart_orig;
992f13f
+ 
992f13f
  #ifdef FEAT_VREPLACE
992f13f
  /*
992f13f
   * Stuff for VREPLACE mode.
992f13f
*** ../vim-7.4.185/src/ops.c	2014-02-11 19:33:03.358353098 +0100
992f13f
--- src/ops.c	2014-02-22 22:39:47.588903502 +0100
992f13f
***************
992f13f
*** 2643,2662 ****
992f13f
  
992f13f
  	/* The user may have moved the cursor before inserting something, try
992f13f
  	 * to adjust the block for that. */
992f13f
! 	if (oap->start.lnum == curbuf->b_op_start.lnum && !bd.is_MAX)
992f13f
  	{
992f13f
  	    if (oap->op_type == OP_INSERT
992f13f
! 		    && oap->start.col != curbuf->b_op_start.col)
992f13f
  	    {
992f13f
! 		oap->start.col = curbuf->b_op_start.col;
992f13f
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
992f13f
  							    - oap->start_vcol;
992f13f
  		oap->start_vcol = getviscol2(oap->start.col, oap->start.coladd);
992f13f
  	    }
992f13f
  	    else if (oap->op_type == OP_APPEND
992f13f
! 		    && oap->end.col >= curbuf->b_op_start.col)
992f13f
  	    {
992f13f
! 		oap->start.col = curbuf->b_op_start.col;
992f13f
  		/* reset pre_textlen to the value of OP_INSERT */
992f13f
  		pre_textlen += bd.textlen;
992f13f
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
992f13f
--- 2643,2662 ----
992f13f
  
992f13f
  	/* The user may have moved the cursor before inserting something, try
992f13f
  	 * to adjust the block for that. */
992f13f
! 	if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX)
992f13f
  	{
992f13f
  	    if (oap->op_type == OP_INSERT
992f13f
! 		    && oap->start.col != curbuf->b_op_start_orig.col)
992f13f
  	    {
992f13f
! 		oap->start.col = curbuf->b_op_start_orig.col;
992f13f
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
992f13f
  							    - oap->start_vcol;
992f13f
  		oap->start_vcol = getviscol2(oap->start.col, oap->start.coladd);
992f13f
  	    }
992f13f
  	    else if (oap->op_type == OP_APPEND
992f13f
! 		    && oap->end.col >= curbuf->b_op_start_orig.col)
992f13f
  	    {
992f13f
! 		oap->start.col = curbuf->b_op_start_orig.col;
992f13f
  		/* reset pre_textlen to the value of OP_INSERT */
992f13f
  		pre_textlen += bd.textlen;
992f13f
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
992f13f
*** ../vim-7.4.185/src/structs.h	2014-02-11 15:10:38.138111836 +0100
992f13f
--- src/structs.h	2014-02-22 22:39:47.588903502 +0100
992f13f
***************
992f13f
*** 1449,1454 ****
992f13f
--- 1449,1455 ----
992f13f
       * start and end of an operator, also used for '[ and ']
992f13f
       */
992f13f
      pos_T	b_op_start;
992f13f
+     pos_T	b_op_start_orig;  /* used for Insstart_orig */
992f13f
      pos_T	b_op_end;
992f13f
  
992f13f
  #ifdef FEAT_VIMINFO
992f13f
*** ../vim-7.4.185/src/version.c	2014-02-22 22:27:20.772904692 +0100
992f13f
--- src/version.c	2014-02-22 22:39:08.932903564 +0100
992f13f
***************
992f13f
*** 740,741 ****
992f13f
--- 740,743 ----
992f13f
  {   /* Add new patch number below this line */
992f13f
+ /**/
992f13f
+     186,
992f13f
  /**/
992f13f
992f13f
-- 
992f13f
Individualists unite!
992f13f
992f13f
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
992f13f
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
992f13f
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
992f13f
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///