]> granicus.if.org Git - vim/commitdiff
patch 8.1.0999: use register one too often and not properly tested v8.1.0999
authorBram Moolenaar <Bram@vim.org>
Fri, 8 Mar 2019 08:50:52 +0000 (09:50 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 8 Mar 2019 08:50:52 +0000 (09:50 +0100)
Problem:    Use register one too often and not properly tested.
Solution:   Do not always use register one when specifying a register.
            (closes #4085)  Add more tests.

src/ops.c
src/testdir/test_registers.vim
src/version.c

index 02c985afef8390788b98435c30fa2e9cdf5ac8bb..3353cf9e266bcaa81ff26ea779976a1e6ed08270 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -1747,7 +1747,6 @@ op_delete(oparg_T *oap)
     struct block_def   bd;
     linenr_T           old_lcount = curbuf->b_ml.ml_line_count;
     int                        did_yank = FALSE;
-    int                        orig_regname = oap->regname;
 
     if (curbuf->b_ml.ml_flags & ML_EMPTY)          /* nothing to do */
        return OK;
@@ -1833,12 +1832,13 @@ op_delete(oparg_T *oap)
 
        /*
         * Put deleted text into register 1 and shift number registers if the
-        * delete contains a line break, or when a regname has been specified.
+        * delete contains a line break, or when using a specific operator (Vi
+        * compatible)
         * Use the register name from before adjust_clip_reg() may have
         * changed it.
         */
-       if (orig_regname != 0 || oap->motion_type == MLINE
-                                  || oap->line_count > 1 || oap->use_reg_one)
+       if (oap->motion_type == MLINE || oap->line_count > 1
+                                                          || oap->use_reg_one)
        {
            shift_delete_registers();
            if (op_yank(oap, TRUE, FALSE) == OK)
index d7b6de5652ce7c639938851d2d65b7bbf67f5bde..1ed0a66d1e7715ef55cce697f4ac5cff6e8133bf 100644 (file)
@@ -42,7 +42,6 @@ func Test_display_registers()
     call assert_match('^\n--- Registers ---\n'
           \ .         '""   a\n'
           \ .         '"0   ba\n'
-          \ .         '"1   b\n'
           \ .         '"a   b\n'
           \ .         '.*'
           \ .         '"-   a\n'
@@ -63,3 +62,87 @@ func Test_display_registers()
 
     bwipe!
 endfunc
+
+func Test_register_one()
+  " delete a line goes into register one
+  new
+  call setline(1, "one")
+  normal dd
+  call assert_equal("one\n", @1)
+
+  " delete a word does not change register one, does change "-
+  call setline(1, "two")
+  normal de
+  call assert_equal("one\n", @1)
+  call assert_equal("two", @-)
+
+  " delete a word with a register does not change register one
+  call setline(1, "three")
+  normal "ade
+  call assert_equal("three", @a)
+  call assert_equal("one\n", @1)
+
+  " delete a word with register DOES change register one with one of a list of
+  " operators
+  " %
+  call setline(1, ["(12)3"])
+  normal "ad%
+  call assert_equal("(12)", @a)
+  call assert_equal("(12)", @1)
+
+  " (
+  call setline(1, ["first second"])
+  normal $"ad(
+  call assert_equal("first secon", @a)
+  call assert_equal("first secon", @1)
+
+  " )
+  call setline(1, ["First Second."])
+  normal gg0"ad)
+  call assert_equal("First Second.", @a)
+  call assert_equal("First Second.", @1)
+
+  " `
+  call setline(1, ["start here."])
+  normal gg0fhmx0"ad`x
+  call assert_equal("start ", @a)
+  call assert_equal("start ", @1)
+
+  " /
+  call setline(1, ["searchX"])
+  exe "normal gg0\"ad/X\<CR>"
+  call assert_equal("search", @a)
+  call assert_equal("search", @1)
+
+  " ?
+  call setline(1, ["Ysearch"])
+  exe "normal gg$\"ad?Y\<CR>"
+  call assert_equal("Ysearc", @a)
+  call assert_equal("Ysearc", @1)
+
+  " n
+  call setline(1, ["Ynext"])
+  normal gg$"adn
+  call assert_equal("Ynex", @a)
+  call assert_equal("Ynex", @1)
+
+  " N
+  call setline(1, ["prevY"])
+  normal gg0"adN
+  call assert_equal("prev", @a)
+  call assert_equal("prev", @1)
+
+  " }
+  call setline(1, ["one", ""])
+  normal gg0"ad}
+  call assert_equal("one\n", @a)
+  call assert_equal("one\n", @1)
+
+  " {
+  call setline(1, ["", "two"])
+  normal 2G$"ad{
+  call assert_equal("\ntw", @a)
+  call assert_equal("\ntw", @1)
+
+  bwipe!
+endfunc
index e57b5762b3284e50259ebfb5451295c08401ac13..e427ffecbe2d6510f6951e8f6371737e5bbe065e 100644 (file)
@@ -779,6 +779,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    999,
 /**/
     998,
 /**/