Skip to content

Commit 3324d0a

Browse files
committed
patch 8.0.1587: inserting from the clipboard doesn't work literally
Problem: inserting from the clipboard doesn't work literally Solution: When pasting from the * or + register always assume literally.
1 parent 201dc67 commit 3324d0a

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

src/ops.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -899,17 +899,21 @@ valid_yank_reg(
899899
*
900900
* If regname is 0 and writing, use register 0
901901
* If regname is 0 and reading, use previous register
902+
*
903+
* Return TRUE when the register should be inserted literally (selection or
904+
* clipboard).
902905
*/
903-
void
906+
int
904907
get_yank_register(int regname, int writing)
905908
{
906909
int i;
910+
int ret = FALSE;
907911

908912
y_append = FALSE;
909913
if ((regname == 0 || regname == '"') && !writing && y_previous != NULL)
910914
{
911915
y_current = y_previous;
912-
return;
916+
return ret;
913917
}
914918
i = regname;
915919
if (VIM_ISDIGIT(i))
@@ -926,10 +930,16 @@ get_yank_register(int regname, int writing)
926930
#ifdef FEAT_CLIPBOARD
927931
/* When selection is not available, use register 0 instead of '*' */
928932
else if (clip_star.available && regname == '*')
933+
{
929934
i = STAR_REGISTER;
935+
ret = TRUE;
936+
}
930937
/* When clipboard is not available, use register 0 instead of '+' */
931938
else if (clip_plus.available && regname == '+')
939+
{
932940
i = PLUS_REGISTER;
941+
ret = TRUE;
942+
}
933943
#endif
934944
#ifdef FEAT_DND
935945
else if (!writing && regname == '~')
@@ -940,6 +950,7 @@ get_yank_register(int regname, int writing)
940950
y_current = &(y_regs[i]);
941951
if (writing) /* remember the register we write into for do_put() */
942952
y_previous = y_current;
953+
return ret;
943954
}
944955

945956
#if defined(FEAT_CLIPBOARD) || defined(PROTO)
@@ -1387,12 +1398,13 @@ put_in_typebuf(
13871398
int
13881399
insert_reg(
13891400
int regname,
1390-
int literally) /* insert literally, not as if typed */
1401+
int literally_arg) /* insert literally, not as if typed */
13911402
{
13921403
long i;
13931404
int retval = OK;
13941405
char_u *arg;
13951406
int allocated;
1407+
int literally = literally_arg;
13961408

13971409
/*
13981410
* It is possible to get into an endless loop by having CTRL-R a in
@@ -1423,7 +1435,8 @@ insert_reg(
14231435
}
14241436
else /* name or number register */
14251437
{
1426-
get_yank_register(regname, FALSE);
1438+
if (get_yank_register(regname, FALSE))
1439+
literally = TRUE;
14271440
if (y_current->y_array == NULL)
14281441
retval = FAIL;
14291442
else
@@ -1580,12 +1593,14 @@ get_spec_reg(
15801593
int
15811594
cmdline_paste_reg(
15821595
int regname,
1583-
int literally, /* Insert text literally instead of "as typed" */
1596+
int literally_arg, /* Insert text literally instead of "as typed" */
15841597
int remcr) /* don't add CR characters */
15851598
{
15861599
long i;
1600+
int literally = literally_arg;
15871601

1588-
get_yank_register(regname, FALSE);
1602+
if (get_yank_register(regname, FALSE))
1603+
literally = TRUE;
15891604
if (y_current->y_array == NULL)
15901605
return FAIL;
15911606

src/proto/ops.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ void set_expr_line(char_u *new_line);
1111
char_u *get_expr_line(void);
1212
char_u *get_expr_line_src(void);
1313
int valid_yank_reg(int regname, int writing);
14-
void get_yank_register(int regname, int writing);
14+
int get_yank_register(int regname, int writing);
1515
int may_get_selection(int regname);
1616
void *get_register(int name, int copy);
1717
void put_register(int name, void *reg);
1818
void free_register(void *reg);
1919
int yank_register_mline(int regname);
2020
int do_record(int c);
2121
int do_execreg(int regname, int colon, int addcr, int silent);
22-
int insert_reg(int regname, int literally);
22+
int insert_reg(int regname, int literally_arg);
2323
int get_spec_reg(int regname, char_u **argp, int *allocated, int errmsg);
2424
int cmdline_paste_reg(int regname, int literally, int remcr);
2525
void adjust_clip_reg(int *rp);

src/testdir/test_paste.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" Tests for bracketed paste.
1+
" Tests for bracketed paste and other forms of pasting.
22

33
" Bracketed paste only works with "xterm". Not in GUI.
44
if has('gui_running')
@@ -66,6 +66,17 @@ func Test_paste_insert_mode()
6666
bwipe!
6767
endfunc
6868

69+
func Test_paste_clipboard()
70+
if !has('clipboard')
71+
return
72+
endif
73+
let @+ = "nasty\<Esc>:!ls\<CR>command"
74+
new
75+
exe "normal i\<C-R>+\<Esc>"
76+
call assert_equal("nasty\<Esc>:!ls\<CR>command", getline(1))
77+
bwipe!
78+
endfunc
79+
6980
func Test_paste_cmdline()
7081
call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt')
7182
call assert_equal("\"afoo\<CR>barb", getreg(':'))

src/version.c

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

767767
static int included_patches[] =
768768
{ /* Add new patch number below this line */
769+
/**/
770+
1587,
769771
/**/
770772
1586,
771773
/**/

0 commit comments

Comments
 (0)