To: vim_dev@googlegroups.com
Subject: Patch 7.4.186
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.4.186 (after 7.4.085)
Problem:    Insert in Visual mode sometimes gives incorrect results.
            (Dominique Pelle)
Solution:   Remember the original insert start position. (Christian Brabandt,
            Dominique Pelle)
Files:      src/edit.c, src/globals.h, src/ops.c, src/structs.h


*** ../vim-7.4.185/src/edit.c	2014-01-23 22:45:54.608127182 +0100
--- src/edit.c	2014-02-22 22:43:52.820903112 +0100
***************
*** 264,269 ****
--- 264,270 ----
  
  static colnr_T	Insstart_textlen;	/* length of line when insert started */
  static colnr_T	Insstart_blank_vcol;	/* vcol for first inserted blank */
+ static int	update_Insstart_orig = TRUE; /* set Insstart_orig to Insstart */
  
  static char_u	*last_insert = NULL;	/* the text of the previous insert,
  					   K_SPECIAL and CSI are escaped */
***************
*** 340,345 ****
--- 341,349 ----
       * error message */
      check_for_delay(TRUE);
  
+     /* set Insstart_orig to Insstart */
+     update_Insstart_orig = TRUE;
+ 
  #ifdef HAVE_SANDBOX
      /* Don't allow inserting in the sandbox. */
      if (sandbox != 0)
***************
*** 631,636 ****
--- 635,643 ----
  	if (arrow_used)	    /* don't repeat insert when arrow key used */
  	    count = 0;
  
+ 	if (update_Insstart_orig)
+ 	    Insstart_orig = Insstart;
+ 
  	if (stop_insert_mode)
  	{
  	    /* ":stopinsert" used or 'insertmode' reset */
***************
*** 6923,6928 ****
--- 6930,6936 ----
      if (end_insert_pos != NULL)
      {
  	curbuf->b_op_start = Insstart;
+ 	curbuf->b_op_start_orig = Insstart_orig;
  	curbuf->b_op_end = *end_insert_pos;
      }
  }
***************
*** 8257,8262 ****
--- 8265,8271 ----
  
  		  /* Need to reset Insstart, esp. because a BS that joins
  		   * a line to the previous one must save for undo. */
+ 		  update_Insstart_orig = FALSE;
  		  Insstart = curwin->w_cursor;
  		  break;
  
*** ../vim-7.4.185/src/globals.h	2014-02-11 15:10:38.130111835 +0100
--- src/globals.h	2014-02-22 23:02:01.644901378 +0100
***************
*** 752,757 ****
--- 752,763 ----
   */
  EXTERN pos_T	Insstart;		/* This is where the latest
  					 * insert/append mode started. */
+ 
+ /* This is where the latest insert/append mode started. In contrast to
+  * Insstart, this won't be reset by certain keys and is needed for
+  * op_insert(), to detect correctly where inserting by the user started. */
+ EXTERN pos_T	Insstart_orig;
+ 
  #ifdef FEAT_VREPLACE
  /*
   * Stuff for VREPLACE mode.
*** ../vim-7.4.185/src/ops.c	2014-02-11 19:33:03.358353098 +0100
--- src/ops.c	2014-02-22 22:39:47.588903502 +0100
***************
*** 2643,2662 ****
  
  	/* The user may have moved the cursor before inserting something, try
  	 * to adjust the block for that. */
! 	if (oap->start.lnum == curbuf->b_op_start.lnum && !bd.is_MAX)
  	{
  	    if (oap->op_type == OP_INSERT
! 		    && oap->start.col != curbuf->b_op_start.col)
  	    {
! 		oap->start.col = curbuf->b_op_start.col;
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
  							    - oap->start_vcol;
  		oap->start_vcol = getviscol2(oap->start.col, oap->start.coladd);
  	    }
  	    else if (oap->op_type == OP_APPEND
! 		    && oap->end.col >= curbuf->b_op_start.col)
  	    {
! 		oap->start.col = curbuf->b_op_start.col;
  		/* reset pre_textlen to the value of OP_INSERT */
  		pre_textlen += bd.textlen;
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
--- 2643,2662 ----
  
  	/* The user may have moved the cursor before inserting something, try
  	 * to adjust the block for that. */
! 	if (oap->start.lnum == curbuf->b_op_start_orig.lnum && !bd.is_MAX)
  	{
  	    if (oap->op_type == OP_INSERT
! 		    && oap->start.col != curbuf->b_op_start_orig.col)
  	    {
! 		oap->start.col = curbuf->b_op_start_orig.col;
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
  							    - oap->start_vcol;
  		oap->start_vcol = getviscol2(oap->start.col, oap->start.coladd);
  	    }
  	    else if (oap->op_type == OP_APPEND
! 		    && oap->end.col >= curbuf->b_op_start_orig.col)
  	    {
! 		oap->start.col = curbuf->b_op_start_orig.col;
  		/* reset pre_textlen to the value of OP_INSERT */
  		pre_textlen += bd.textlen;
  		pre_textlen -= getviscol2(oap->start.col, oap->start.coladd)
*** ../vim-7.4.185/src/structs.h	2014-02-11 15:10:38.138111836 +0100
--- src/structs.h	2014-02-22 22:39:47.588903502 +0100
***************
*** 1449,1454 ****
--- 1449,1455 ----
       * start and end of an operator, also used for '[ and ']
       */
      pos_T	b_op_start;
+     pos_T	b_op_start_orig;  /* used for Insstart_orig */
      pos_T	b_op_end;
  
  #ifdef FEAT_VIMINFO
*** ../vim-7.4.185/src/version.c	2014-02-22 22:27:20.772904692 +0100
--- src/version.c	2014-02-22 22:39:08.932903564 +0100
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     186,
  /**/

-- 
Individualists unite!

 /// Bram Moolenaar -- Bram@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    ///
