vim-patch:9.1.1216: Pasting the '.' register multiple times may not work

Problem:  Pasting the '.' register multiple times may work incorrectly
          when the last insert starts with Ctrl-D and ends with '0'.
          (after 9.1.1212)
Solution: Restore the missing assignment (zeertzjq).

closes: vim/vim#16908

61b3544424
This commit is contained in:
zeertzjq
2025-03-18 06:07:13 +08:00
parent 59d8d50c5b
commit d717f8605a
2 changed files with 32 additions and 4 deletions

View File

@@ -2708,20 +2708,21 @@ int stuff_inserted(int c, int count, int no_esc)
} }
if (insert->size > 0) { if (insert->size > 0) {
char *p;
// look for the last ESC in 'insert' // look for the last ESC in 'insert'
for (p = insert->data + (insert->size - 1); p >= insert->data; p--) { for (char *p = insert->data + insert->size - 1; p >= insert->data; p--) {
if (*p == ESC) { if (*p == ESC) {
insert->size = (size_t)(p - insert->data); insert->size = (size_t)(p - insert->data);
break; break;
} }
} }
}
if (insert->size > 0) {
char *p = insert->data + insert->size - 1;
// when the last char is either "0" or "^" it will be quoted if no ESC // when the last char is either "0" or "^" it will be quoted if no ESC
// comes after it OR if it will inserted more than once and "ptr" // comes after it OR if it will inserted more than once and "ptr"
// starts with ^D. -- Acevedo // starts with ^D. -- Acevedo
if (p >= insert->data if ((*p == '0' || *p == '^')
&& (*p == '0' || *p == '^')
&& (no_esc || (*insert->data == Ctrl_D && count > 1))) { && (no_esc || (*insert->data == Ctrl_D && count > 1))) {
last = *p; last = *p;
insert->size--; insert->size--;

View File

@@ -328,4 +328,31 @@ func Test_put_list()
put! =l put! =l
call assert_equal(['a', 'b', 'c', ''], getline(1, '$')) call assert_equal(['a', 'b', 'c', ''], getline(1, '$'))
bw! bw!
endfunc
" Test pasting the '.' register
func Test_put_inserted()
new
for s in ['', '…', '0', '^', '+0', '+^', '…0', '…^']
call setline(1, 'foobar')
exe $"normal! A{s}\<Esc>"
call assert_equal($'foobar{s}', getline(1))
normal! ".p
call assert_equal($'foobar{s}{s}', getline(1))
normal! ".2p
call assert_equal($'foobar{s}{s}{s}{s}', getline(1))
endfor
for s in ['0', '^', '+0', '+^', '…0', '…^']
call setline(1, "\t\t\t\t\tfoobar")
exe $"normal! A\<C-D>{s}\<Esc>"
call assert_equal($"\t\t\t\tfoobar{s}", getline(1))
normal! ".p
call assert_equal($"\t\t\tfoobar{s}{s}", getline(1))
normal! ".2p
call assert_equal($"\tfoobar{s}{s}{s}{s}", getline(1))
endfor
bwipe!
endfunc endfunc