]> granicus.if.org Git - vim/commitdiff
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line v8.1.0125
authorBram Moolenaar <Bram@vim.org>
Thu, 28 Jun 2018 17:26:28 +0000 (19:26 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 28 Jun 2018 17:26:28 +0000 (19:26 +0200)
Problem:    Virtual edit replace with multi-byte fails at end of line. (Lukas
            Werling)
Solution:   use ins_char() to add the character. (Christian Brabandt,
            closes #3114)  Rename PCHAR() to PBYTE() to avoid mistakes like
            this.

src/macros.h
src/ops.c
src/testdir/test_virtualedit.vim
src/version.c

index fcd1a829da76b83f9df7b733ea95b2746805c328..c91b4b62058e0ecf7b1e19307f7f6ed21f889f68 100644 (file)
@@ -14,9 +14,9 @@
  */
 
 /*
- * PCHAR(lp, c) - put character 'c' at position 'lp'
+ * PBYTE(lp, c) - put byte 'c' at position 'lp'
  */
-#define PCHAR(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
+#define PBYTE(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
 
 /*
  * Position comparisons
index 73f73d2f92d600da35650919364797068df0486c..2e08a53291235006141fc0553132a471b1fb1a9e 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -2146,6 +2146,25 @@ mb_adjust_opend(oparg_T *oap)
 #endif
 
 #if defined(FEAT_VISUALEXTRA) || defined(PROTO)
+
+# ifdef FEAT_MBYTE
+/*
+ * Replace the character under the cursor with "c".
+ * This takes care of multi-byte characters.
+ */
+    static void
+replace_character(int c)
+{
+    int n = State;
+
+    State = REPLACE;
+    ins_char(c);
+    State = n;
+    /* Backup to the replaced character. */
+    dec_cursor();
+}
+
+# endif
 /*
  * Replace a whole area with one character.
  */
@@ -2331,12 +2350,7 @@ op_replace(oparg_T *oap, int c)
                     * with a multi-byte and the other way around. */
                    if (curwin->w_cursor.lnum == oap->end.lnum)
                        oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
-                   n = State;
-                   State = REPLACE;
-                   ins_char(c);
-                   State = n;
-                   /* Backup to the replaced character. */
-                   dec_cursor();
+                   replace_character(c);
                }
                else
 #endif
@@ -2358,7 +2372,7 @@ op_replace(oparg_T *oap, int c)
                            getvpos(&oap->end, end_vcol);
                    }
 #endif
-                   PCHAR(curwin->w_cursor, c);
+                   PBYTE(curwin->w_cursor, c);
                }
            }
 #ifdef FEAT_VIRTUALEDIT
@@ -2377,9 +2391,14 @@ op_replace(oparg_T *oap, int c)
                curwin->w_cursor.col -= (virtcols + 1);
                for (; virtcols >= 0; virtcols--)
                {
-                   PCHAR(curwin->w_cursor, c);
-                   if (inc(&curwin->w_cursor) == -1)
-                       break;
+#ifdef FEAT_MBYTE
+                   if ((*mb_char2len)(c) > 1)
+                      replace_character(c);
+                   else
+ #endif
+                       PBYTE(curwin->w_cursor, c);
+                  if (inc(&curwin->w_cursor) == -1)
+                      break;
                }
            }
 #endif
@@ -2619,7 +2638,7 @@ swapchar(int op_type, pos_T *pos)
        }
        else
 #endif
-           PCHAR(*pos, nc);
+           PBYTE(*pos, nc);
        return TRUE;
     }
     return FALSE;
index d49025237b7ef2b1e0536d1970d2c6512deb8107..abe79f6a4ad8b24be423546e4fd5cd33deaf2ee9 100644 (file)
@@ -42,6 +42,22 @@ func Test_paste_end_of_line()
   set virtualedit=
 endfunc
 
+func Test_replace_end_of_line()
+  new
+  set virtualedit=all
+  call setline(1, range(20))
+  exe "normal! gg2jv10lr-"
+  call assert_equal(["1", "-----------", "3"], getline(2,4))
+  if has('multi_byte')
+    call setline(1, range(20))
+    exe "normal! gg2jv10lr\<c-k>hh"
+    call assert_equal(["1", "───────────", "3"], getline(2,4))
+  endif
+
+  bwipe!
+  set virtualedit=
+endfunc
+
 func Test_edit_CTRL_G()
   new
   set virtualedit=insert
index 86e24fdc1086622ed66ef9d001ed63b9c71e833c..31db8405326332a1ece31df938fc5026cdb99cb7 100644 (file)
@@ -789,6 +789,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    125,
 /**/
     124,
 /**/