Skip to content

Commit 9d7fdd4

Browse files
committed
patch 8.1.0999: use register one too often and not properly tested
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.
1 parent 19a6685 commit 9d7fdd4

3 files changed

Lines changed: 90 additions & 5 deletions

File tree

src/ops.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,6 @@ op_delete(oparg_T *oap)
17471747
struct block_def bd;
17481748
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
17491749
int did_yank = FALSE;
1750-
int orig_regname = oap->regname;
17511750

17521751
if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */
17531752
return OK;
@@ -1833,12 +1832,13 @@ op_delete(oparg_T *oap)
18331832

18341833
/*
18351834
* Put deleted text into register 1 and shift number registers if the
1836-
* delete contains a line break, or when a regname has been specified.
1835+
* delete contains a line break, or when using a specific operator (Vi
1836+
* compatible)
18371837
* Use the register name from before adjust_clip_reg() may have
18381838
* changed it.
18391839
*/
1840-
if (orig_regname != 0 || oap->motion_type == MLINE
1841-
|| oap->line_count > 1 || oap->use_reg_one)
1840+
if (oap->motion_type == MLINE || oap->line_count > 1
1841+
|| oap->use_reg_one)
18421842
{
18431843
shift_delete_registers();
18441844
if (op_yank(oap, TRUE, FALSE) == OK)

src/testdir/test_registers.vim

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func Test_display_registers()
4242
call assert_match('^\n--- Registers ---\n'
4343
\ . '"" a\n'
4444
\ . '"0 ba\n'
45-
\ . '"1 b\n'
4645
\ . '"a b\n'
4746
\ . '.*'
4847
\ . '"- a\n'
@@ -63,3 +62,87 @@ func Test_display_registers()
6362

6463
bwipe!
6564
endfunc
65+
66+
func Test_register_one()
67+
" delete a line goes into register one
68+
new
69+
call setline(1, "one")
70+
normal dd
71+
call assert_equal("one\n", @1)
72+
73+
" delete a word does not change register one, does change "-
74+
call setline(1, "two")
75+
normal de
76+
call assert_equal("one\n", @1)
77+
call assert_equal("two", @-)
78+
79+
" delete a word with a register does not change register one
80+
call setline(1, "three")
81+
normal "ade
82+
call assert_equal("three", @a)
83+
call assert_equal("one\n", @1)
84+
85+
" delete a word with register DOES change register one with one of a list of
86+
" operators
87+
" %
88+
call setline(1, ["(12)3"])
89+
normal "ad%
90+
call assert_equal("(12)", @a)
91+
call assert_equal("(12)", @1)
92+
93+
" (
94+
call setline(1, ["first second"])
95+
normal $"ad(
96+
call assert_equal("first secon", @a)
97+
call assert_equal("first secon", @1)
98+
99+
" )
100+
call setline(1, ["First Second."])
101+
normal gg0"ad)
102+
call assert_equal("First Second.", @a)
103+
call assert_equal("First Second.", @1)
104+
105+
" `
106+
call setline(1, ["start here."])
107+
normal gg0fhmx0"ad`x
108+
call assert_equal("start ", @a)
109+
call assert_equal("start ", @1)
110+
111+
" /
112+
call setline(1, ["searchX"])
113+
exe "normal gg0\"ad/X\<CR>"
114+
call assert_equal("search", @a)
115+
call assert_equal("search", @1)
116+
117+
" ?
118+
call setline(1, ["Ysearch"])
119+
exe "normal gg$\"ad?Y\<CR>"
120+
call assert_equal("Ysearc", @a)
121+
call assert_equal("Ysearc", @1)
122+
123+
" n
124+
call setline(1, ["Ynext"])
125+
normal gg$"adn
126+
call assert_equal("Ynex", @a)
127+
call assert_equal("Ynex", @1)
128+
129+
" N
130+
call setline(1, ["prevY"])
131+
normal gg0"adN
132+
call assert_equal("prev", @a)
133+
call assert_equal("prev", @1)
134+
135+
" }
136+
call setline(1, ["one", ""])
137+
normal gg0"ad}
138+
call assert_equal("one\n", @a)
139+
call assert_equal("one\n", @1)
140+
141+
" {
142+
call setline(1, ["", "two"])
143+
normal 2G$"ad{
144+
call assert_equal("\ntw", @a)
145+
call assert_equal("\ntw", @1)
146+
147+
bwipe!
148+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ static char *(features[]) =
779779

780780
static int included_patches[] =
781781
{ /* Add new patch number below this line */
782+
/**/
783+
999,
782784
/**/
783785
998,
784786
/**/

0 commit comments

Comments
 (0)