Blob Blame History Raw
To: vim-dev@vim.org
Subject: patch 7.1.107
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.1.107
Problem:    When doing a block selection and using "s" to change the text,
	    while triggering auto-indenting, causes the wrong text to be
	    repeated in other lines. (Adri Verhoef)
Solution:   Compute the change of indent and compensate for that.
Files:	    src/ops.c


*** ../vim-7.1.106/src/ops.c	Thu Jun 28 22:14:28 2007
--- src/ops.c	Thu Aug 30 11:41:10 2007
***************
*** 2477,2483 ****
  
  	/*
  	 * Spaces and tabs in the indent may have changed to other spaces and
! 	 * tabs.  Get the starting column again and correct the lenght.
  	 * Don't do this when "$" used, end-of-line will have changed.
  	 */
  	block_prep(oap, &bd2, oap->start.lnum, TRUE);
--- 2477,2483 ----
  
  	/*
  	 * Spaces and tabs in the indent may have changed to other spaces and
! 	 * tabs.  Get the starting column again and correct the length.
  	 * Don't do this when "$" used, end-of-line will have changed.
  	 */
  	block_prep(oap, &bd2, oap->start.lnum, TRUE);
***************
*** 2534,2540 ****
  #ifdef FEAT_VISUALEXTRA
      long		offset;
      linenr_T		linenr;
!     long		ins_len, pre_textlen = 0;
      char_u		*firstline;
      char_u		*ins_text, *newp, *oldp;
      struct block_def	bd;
--- 2534,2542 ----
  #ifdef FEAT_VISUALEXTRA
      long		offset;
      linenr_T		linenr;
!     long		ins_len;
!     long		pre_textlen = 0;
!     long		pre_indent = 0;
      char_u		*firstline;
      char_u		*ins_text, *newp, *oldp;
      struct block_def	bd;
***************
*** 2579,2585 ****
  						    || gchar_cursor() == NUL))
  	    coladvance_force(getviscol());
  # endif
! 	pre_textlen = (long)STRLEN(ml_get(oap->start.lnum));
  	bd.textcol = curwin->w_cursor.col;
      }
  #endif
--- 2581,2589 ----
  						    || gchar_cursor() == NUL))
  	    coladvance_force(getviscol());
  # endif
! 	firstline = ml_get(oap->start.lnum);
! 	pre_textlen = (long)STRLEN(firstline);
! 	pre_indent = (long)(skipwhite(firstline) - firstline);
  	bd.textcol = curwin->w_cursor.col;
      }
  #endif
***************
*** 2598,2610 ****
       */
      if (oap->block_mode && oap->start.lnum != oap->end.lnum)
      {
  	firstline = ml_get(oap->start.lnum);
! 	/*
! 	 * Subsequent calls to ml_get() flush the firstline data - take a
! 	 * copy of the required bit.
! 	 */
! 	if ((ins_len = (long)STRLEN(firstline) - pre_textlen) > 0)
  	{
  	    if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL)
  	    {
  		vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len);
--- 2602,2623 ----
       */
      if (oap->block_mode && oap->start.lnum != oap->end.lnum)
      {
+ 	/* Auto-indenting may have changed the indent.  If the cursor was past
+ 	 * the indent, exclude that indent change from the inserted text. */
  	firstline = ml_get(oap->start.lnum);
! 	if (bd.textcol > pre_indent)
! 	{
! 	    long new_indent = (long)(skipwhite(firstline) - firstline);
! 
! 	    pre_textlen += new_indent - pre_indent;
! 	    bd.textcol += new_indent - pre_indent;
! 	}
! 
! 	ins_len = (long)STRLEN(firstline) - pre_textlen;
! 	if (ins_len > 0)
  	{
+ 	    /* Subsequent calls to ml_get() flush the firstline data - take a
+ 	     * copy of the inserted text.  */
  	    if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL)
  	    {
  		vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len);
*** ../vim-7.1.106/src/version.c	Thu Sep 13 22:04:30 2007
--- src/version.c	Thu Sep 13 22:38:28 2007
***************
*** 668,669 ****
--- 668,671 ----
  {   /* Add new patch number below this line */
+ /**/
+     107,
  /**/

-- 
Windows
M!uqoms

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///