f777d54
To: vim-dev@vim.org
f777d54
Subject: patch 7.1.107
f777d54
Fcc: outbox
f777d54
From: Bram Moolenaar <Bram@moolenaar.net>
f777d54
Mime-Version: 1.0
f777d54
Content-Type: text/plain; charset=ISO-8859-1
f777d54
Content-Transfer-Encoding: 8bit
f777d54
------------
f777d54
f777d54
Patch 7.1.107
f777d54
Problem:    When doing a block selection and using "s" to change the text,
f777d54
	    while triggering auto-indenting, causes the wrong text to be
f777d54
	    repeated in other lines. (Adri Verhoef)
f777d54
Solution:   Compute the change of indent and compensate for that.
f777d54
Files:	    src/ops.c
f777d54
f777d54
f777d54
*** ../vim-7.1.106/src/ops.c	Thu Jun 28 22:14:28 2007
f777d54
--- src/ops.c	Thu Aug 30 11:41:10 2007
f777d54
***************
f777d54
*** 2477,2483 ****
f777d54
  
f777d54
  	/*
f777d54
  	 * Spaces and tabs in the indent may have changed to other spaces and
f777d54
! 	 * tabs.  Get the starting column again and correct the lenght.
f777d54
  	 * Don't do this when "$" used, end-of-line will have changed.
f777d54
  	 */
f777d54
  	block_prep(oap, &bd2, oap->start.lnum, TRUE);
f777d54
--- 2477,2483 ----
f777d54
  
f777d54
  	/*
f777d54
  	 * Spaces and tabs in the indent may have changed to other spaces and
f777d54
! 	 * tabs.  Get the starting column again and correct the length.
f777d54
  	 * Don't do this when "$" used, end-of-line will have changed.
f777d54
  	 */
f777d54
  	block_prep(oap, &bd2, oap->start.lnum, TRUE);
f777d54
***************
f777d54
*** 2534,2540 ****
f777d54
  #ifdef FEAT_VISUALEXTRA
f777d54
      long		offset;
f777d54
      linenr_T		linenr;
f777d54
!     long		ins_len, pre_textlen = 0;
f777d54
      char_u		*firstline;
f777d54
      char_u		*ins_text, *newp, *oldp;
f777d54
      struct block_def	bd;
f777d54
--- 2534,2542 ----
f777d54
  #ifdef FEAT_VISUALEXTRA
f777d54
      long		offset;
f777d54
      linenr_T		linenr;
f777d54
!     long		ins_len;
f777d54
!     long		pre_textlen = 0;
f777d54
!     long		pre_indent = 0;
f777d54
      char_u		*firstline;
f777d54
      char_u		*ins_text, *newp, *oldp;
f777d54
      struct block_def	bd;
f777d54
***************
f777d54
*** 2579,2585 ****
f777d54
  						    || gchar_cursor() == NUL))
f777d54
  	    coladvance_force(getviscol());
f777d54
  # endif
f777d54
! 	pre_textlen = (long)STRLEN(ml_get(oap->start.lnum));
f777d54
  	bd.textcol = curwin->w_cursor.col;
f777d54
      }
f777d54
  #endif
f777d54
--- 2581,2589 ----
f777d54
  						    || gchar_cursor() == NUL))
f777d54
  	    coladvance_force(getviscol());
f777d54
  # endif
f777d54
! 	firstline = ml_get(oap->start.lnum);
f777d54
! 	pre_textlen = (long)STRLEN(firstline);
f777d54
! 	pre_indent = (long)(skipwhite(firstline) - firstline);
f777d54
  	bd.textcol = curwin->w_cursor.col;
f777d54
      }
f777d54
  #endif
f777d54
***************
f777d54
*** 2598,2610 ****
f777d54
       */
f777d54
      if (oap->block_mode && oap->start.lnum != oap->end.lnum)
f777d54
      {
f777d54
  	firstline = ml_get(oap->start.lnum);
f777d54
! 	/*
f777d54
! 	 * Subsequent calls to ml_get() flush the firstline data - take a
f777d54
! 	 * copy of the required bit.
f777d54
! 	 */
f777d54
! 	if ((ins_len = (long)STRLEN(firstline) - pre_textlen) > 0)
f777d54
  	{
f777d54
  	    if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL)
f777d54
  	    {
f777d54
  		vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len);
f777d54
--- 2602,2623 ----
f777d54
       */
f777d54
      if (oap->block_mode && oap->start.lnum != oap->end.lnum)
f777d54
      {
f777d54
+ 	/* Auto-indenting may have changed the indent.  If the cursor was past
f777d54
+ 	 * the indent, exclude that indent change from the inserted text. */
f777d54
  	firstline = ml_get(oap->start.lnum);
f777d54
! 	if (bd.textcol > pre_indent)
f777d54
! 	{
f777d54
! 	    long new_indent = (long)(skipwhite(firstline) - firstline);
f777d54
! 
f777d54
! 	    pre_textlen += new_indent - pre_indent;
f777d54
! 	    bd.textcol += new_indent - pre_indent;
f777d54
! 	}
f777d54
! 
f777d54
! 	ins_len = (long)STRLEN(firstline) - pre_textlen;
f777d54
! 	if (ins_len > 0)
f777d54
  	{
f777d54
+ 	    /* Subsequent calls to ml_get() flush the firstline data - take a
f777d54
+ 	     * copy of the inserted text.  */
f777d54
  	    if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL)
f777d54
  	    {
f777d54
  		vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len);
f777d54
*** ../vim-7.1.106/src/version.c	Thu Sep 13 22:04:30 2007
f777d54
--- src/version.c	Thu Sep 13 22:38:28 2007
f777d54
***************
f777d54
*** 668,669 ****
f777d54
--- 668,671 ----
f777d54
  {   /* Add new patch number below this line */
f777d54
+ /**/
f777d54
+     107,
f777d54
  /**/
f777d54
f777d54
-- 
f777d54
Windows
f777d54
M!uqoms
f777d54
f777d54
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
f777d54
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
f777d54
\\\        download, build and distribute -- http://www.A-A-P.org        ///
f777d54
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///