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

Move cursor if replace char

Expand Messages
  • Yasuhiro Matsumoto
    Hi. if replacing double-byte with single-bute, cursor move next. I made patch. ... *************** *** 4533,4539 **** else if (IsLeadByte(prechar)) {
    Message 1 of 2 , Apr 14, 2000
    • 0 Attachment
      Hi.

      if replacing double-byte with single-bute,
      cursor move next.

      I made patch.

      -------------------------------------------------
      *** src.orig/normal.c Fri Apr 14 15:53:38 2000
      --- src/normal.c Fri Apr 14 16:12:58 2000
      ***************
      *** 4533,4539 ****
      else if (IsLeadByte(prechar))
      {
      (void)del_char(TRUE);
      ! ++curwin->w_cursor.col;
      }
      }
      #endif
      --- 4533,4540 ----
      else if (IsLeadByte(prechar))
      {
      (void)del_char(TRUE);
      ! if (!IsLeadByte(ptr[curwin->w_cursor.col]))
      ! ++curwin->w_cursor.col;
      }
      }
      #endif
    • Bram Moolenaar
      ... I see the problem. I notice that the call to del_char() isn t really necessary, a mch_memmove() is simpler and avoids that the cursor moves. Hmm, now that
      Message 2 of 2 , Apr 14, 2000
      • 0 Attachment
        Yasuhiro Matsumoto wrote:

        > if replacing double-byte with single-bute,
        > cursor move next.

        I see the problem. I notice that the call to del_char() isn't really
        necessary, a mch_memmove() is simpler and avoids that the cursor moves.

        Hmm, now that I look at this, I see another problem: When using a count for
        the "r" command, and replacing a single-byte character with a double-byte
        character, the ins_char() will have made the pointer invalid and strange
        things might happen.

        Try this code instead (around line 4519 in normal.c):

        showmatch();
        ++curwin->w_cursor.col;
        #ifdef MULTI_BYTE
        if (is_dbcs)
        {
        /* Handle three situations:
        * 1. replace double-byte with double-byte: set trailbyte.
        * 2. replace single-byte with double-byte: insert trailbyte.
        * 3. replace double-byte with single-byte: delete char.
        */
        if (trailbyte != NUL)
        {
        if (IsLeadByte(prechar))
        {
        ptr[curwin->w_cursor.col] = trailbyte;
        ++curwin->w_cursor.col;
        }
        else
        {
        (void)ins_char(trailbyte);
        if (n > 1)
        /* pointer will have changed, get it again */
        ptr = ml_get_buf(curbuf, curwin->w_cursor.lnum,
        TRUE);
        }
        }
        else if (IsLeadByte(prechar))
        {
        mch_memmove(ptr + curwin->w_cursor.col,
        ptr + curwin->w_cursor.col + 1,
        STRLEN(ptr + curwin->w_cursor.col));
        }
        }
        #endif
        }
        --curwin->w_cursor.col; /* cursor on the last replaced char */

        Please check that this works correctly!

        --
        hundred-and-one symptoms of being an internet addict:
        46. Your wife makes a new rule: "The computer cannot come to bed."

        /-/-- Bram Moolenaar --- Bram@... --- http://www.moolenaar.net --\-\
        \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/
      Your message has been successfully submitted and would be delivered to recipients shortly.