Loading ...
Sorry, an error occurred while loading the content.

Patch 6.2.517

Expand Messages
  • Bram Moolenaar
    Patch 6.2.517 Problem: Using r* in Visual mode on multi-byte characters replaces too many characters. In Visual Block mode replacing with a multi-byte
    Message 1 of 1 , Apr 30, 2004
    • 0 Attachment
      Patch 6.2.517
      Problem: Using "r*" in Visual mode on multi-byte characters replaces
      too many characters. In Visual Block mode replacing with a
      multi-byte character doesn't work.
      Solution: Adjust the operator end for the difference in byte length of the
      original and the replaced character. Insert all bytes of a
      multi-byte character, take care of double-wide characters.
      Files: src/ops.c


      *** ../vim-6.2.516/src/ops.c Fri Apr 23 15:19:46 2004
      --- src/ops.c Fri Apr 30 17:21:32 2004
      ***************
      *** 1925,1930 ****
      --- 1925,1933 ----
      int c;
      {
      int n, numc;
      + #ifdef FEAT_MBYTE
      + int num_chars;
      + #endif
      char_u *newp, *oldp;
      size_t oldlen;
      struct block_def bd;
      ***************
      *** 1978,1988 ****
      #ifdef FEAT_VIRTUALEDIT
      && !bd.is_oneChar
      #endif
      ! && bd.end_char_vcols > 0 ? bd.end_char_vcols - 1 : 0);
      /* Figure out how many characters to replace. */
      numc = oap->end_vcol - oap->start_vcol + 1;
      if (bd.is_short && (!virtual_op || bd.is_MAX))
      numc -= (oap->end_vcol - bd.end_vcol) + 1;
      /* oldlen includes textlen, so don't double count */
      n += numc - bd.textlen;

      --- 1981,2009 ----
      #ifdef FEAT_VIRTUALEDIT
      && !bd.is_oneChar
      #endif
      ! && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0;
      /* Figure out how many characters to replace. */
      numc = oap->end_vcol - oap->start_vcol + 1;
      if (bd.is_short && (!virtual_op || bd.is_MAX))
      numc -= (oap->end_vcol - bd.end_vcol) + 1;
      +
      + #ifdef FEAT_MBYTE
      + /* A double-wide character can be replaced only up to half the
      + * times. */
      + if ((*mb_char2cells)(c) > 1)
      + {
      + if ((numc & 1) && !bd.is_short)
      + {
      + ++bd.endspaces;
      + ++n;
      + }
      + numc = numc / 2;
      + }
      +
      + /* Compute bytes needed, move character count to num_chars. */
      + num_chars = numc;
      + numc *= (*mb_char2len)(c);
      + #endif
      /* oldlen includes textlen, so don't double count */
      n += numc - bd.textlen;

      ***************
      *** 1998,2004 ****
      /* insert pre-spaces */
      copy_spaces(newp + bd.textcol, (size_t)bd.startspaces);
      /* insert replacement chars CHECK FOR ALLOCATED SPACE */
      ! copy_chars(newp + STRLEN(newp), (size_t)numc, c);
      if (!bd.is_short)
      {
      /* insert post-spaces */
      --- 2019,2034 ----
      /* insert pre-spaces */
      copy_spaces(newp + bd.textcol, (size_t)bd.startspaces);
      /* insert replacement chars CHECK FOR ALLOCATED SPACE */
      ! #ifdef FEAT_MBYTE
      ! if (has_mbyte)
      ! {
      ! n = STRLEN(newp);
      ! while (--num_chars >= 0)
      ! n += (*mb_char2bytes)(c, newp + n);
      ! }
      ! else
      ! #endif
      ! copy_chars(newp + STRLEN(newp), (size_t)numc, c);
      if (!bd.is_short)
      {
      /* insert post-spaces */
      ***************
      *** 2036,2041 ****
      --- 2066,2072 ----
      {
      /* This is slow, but it handles replacing a single-byte
      * with a multi-byte and the other way around. */
      + oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
      n = State;
      State = REPLACE;
      ins_char(c);
      *** ../vim-6.2.516/src/version.c Thu Apr 29 16:36:50 2004
      --- src/version.c Fri Apr 30 19:38:27 2004
      ***************
      *** 639,640 ****
      --- 639,642 ----
      { /* Add new patch number below this line */
      + /**/
      + 517,
      /**/

      --
      hundred-and-one symptoms of being an internet addict:
      80. At parties, you introduce your spouse as your "service provider."

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
      \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
    Your message has been successfully submitted and would be delivered to recipients shortly.