Mercurial > vim
comparison src/ops.c @ 13425:bb789ed5113a v8.0.1587
patch 8.0.1587: inserting from the clipboard doesn't work literally
commit https://github.com/vim/vim/commit/3324d0a86421a634572758dcfde917547f4d4c67
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Mar 6 19:51:13 2018 +0100
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.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 06 Mar 2018 20:00:07 +0100 |
parents | 69517d67421f |
children | e76499e85744 |
comparison
equal
deleted
inserted
replaced
13424:22b13b27d9fe | 13425:bb789ed5113a |
---|---|
897 * Cannot handle the '_' register. | 897 * Cannot handle the '_' register. |
898 * Must only be called with a valid register name! | 898 * Must only be called with a valid register name! |
899 * | 899 * |
900 * If regname is 0 and writing, use register 0 | 900 * If regname is 0 and writing, use register 0 |
901 * If regname is 0 and reading, use previous register | 901 * If regname is 0 and reading, use previous register |
902 */ | 902 * |
903 void | 903 * Return TRUE when the register should be inserted literally (selection or |
904 * clipboard). | |
905 */ | |
906 int | |
904 get_yank_register(int regname, int writing) | 907 get_yank_register(int regname, int writing) |
905 { | 908 { |
906 int i; | 909 int i; |
910 int ret = FALSE; | |
907 | 911 |
908 y_append = FALSE; | 912 y_append = FALSE; |
909 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | 913 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) |
910 { | 914 { |
911 y_current = y_previous; | 915 y_current = y_previous; |
912 return; | 916 return ret; |
913 } | 917 } |
914 i = regname; | 918 i = regname; |
915 if (VIM_ISDIGIT(i)) | 919 if (VIM_ISDIGIT(i)) |
916 i -= '0'; | 920 i -= '0'; |
917 else if (ASCII_ISLOWER(i)) | 921 else if (ASCII_ISLOWER(i)) |
924 else if (regname == '-') | 928 else if (regname == '-') |
925 i = DELETION_REGISTER; | 929 i = DELETION_REGISTER; |
926 #ifdef FEAT_CLIPBOARD | 930 #ifdef FEAT_CLIPBOARD |
927 /* When selection is not available, use register 0 instead of '*' */ | 931 /* When selection is not available, use register 0 instead of '*' */ |
928 else if (clip_star.available && regname == '*') | 932 else if (clip_star.available && regname == '*') |
933 { | |
929 i = STAR_REGISTER; | 934 i = STAR_REGISTER; |
935 ret = TRUE; | |
936 } | |
930 /* When clipboard is not available, use register 0 instead of '+' */ | 937 /* When clipboard is not available, use register 0 instead of '+' */ |
931 else if (clip_plus.available && regname == '+') | 938 else if (clip_plus.available && regname == '+') |
939 { | |
932 i = PLUS_REGISTER; | 940 i = PLUS_REGISTER; |
941 ret = TRUE; | |
942 } | |
933 #endif | 943 #endif |
934 #ifdef FEAT_DND | 944 #ifdef FEAT_DND |
935 else if (!writing && regname == '~') | 945 else if (!writing && regname == '~') |
936 i = TILDE_REGISTER; | 946 i = TILDE_REGISTER; |
937 #endif | 947 #endif |
938 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | 948 else /* not 0-9, a-z, A-Z or '-': use register 0 */ |
939 i = 0; | 949 i = 0; |
940 y_current = &(y_regs[i]); | 950 y_current = &(y_regs[i]); |
941 if (writing) /* remember the register we write into for do_put() */ | 951 if (writing) /* remember the register we write into for do_put() */ |
942 y_previous = y_current; | 952 y_previous = y_current; |
953 return ret; | |
943 } | 954 } |
944 | 955 |
945 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | 956 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
946 /* | 957 /* |
947 * When "regname" is a clipboard register, obtain the selection. If it's not | 958 * When "regname" is a clipboard register, obtain the selection. If it's not |
1385 * return FAIL for failure, OK otherwise | 1396 * return FAIL for failure, OK otherwise |
1386 */ | 1397 */ |
1387 int | 1398 int |
1388 insert_reg( | 1399 insert_reg( |
1389 int regname, | 1400 int regname, |
1390 int literally) /* insert literally, not as if typed */ | 1401 int literally_arg) /* insert literally, not as if typed */ |
1391 { | 1402 { |
1392 long i; | 1403 long i; |
1393 int retval = OK; | 1404 int retval = OK; |
1394 char_u *arg; | 1405 char_u *arg; |
1395 int allocated; | 1406 int allocated; |
1407 int literally = literally_arg; | |
1396 | 1408 |
1397 /* | 1409 /* |
1398 * It is possible to get into an endless loop by having CTRL-R a in | 1410 * It is possible to get into an endless loop by having CTRL-R a in |
1399 * register a and then, in insert mode, doing CTRL-R a. | 1411 * register a and then, in insert mode, doing CTRL-R a. |
1400 * If you hit CTRL-C, the loop will be broken here. | 1412 * If you hit CTRL-C, the loop will be broken here. |
1421 if (allocated) | 1433 if (allocated) |
1422 vim_free(arg); | 1434 vim_free(arg); |
1423 } | 1435 } |
1424 else /* name or number register */ | 1436 else /* name or number register */ |
1425 { | 1437 { |
1426 get_yank_register(regname, FALSE); | 1438 if (get_yank_register(regname, FALSE)) |
1439 literally = TRUE; | |
1427 if (y_current->y_array == NULL) | 1440 if (y_current->y_array == NULL) |
1428 retval = FAIL; | 1441 retval = FAIL; |
1429 else | 1442 else |
1430 { | 1443 { |
1431 for (i = 0; i < y_current->y_size; ++i) | 1444 for (i = 0; i < y_current->y_size; ++i) |
1578 * return FAIL for failure, OK otherwise | 1591 * return FAIL for failure, OK otherwise |
1579 */ | 1592 */ |
1580 int | 1593 int |
1581 cmdline_paste_reg( | 1594 cmdline_paste_reg( |
1582 int regname, | 1595 int regname, |
1583 int literally, /* Insert text literally instead of "as typed" */ | 1596 int literally_arg, /* Insert text literally instead of "as typed" */ |
1584 int remcr) /* don't add CR characters */ | 1597 int remcr) /* don't add CR characters */ |
1585 { | 1598 { |
1586 long i; | 1599 long i; |
1587 | 1600 int literally = literally_arg; |
1588 get_yank_register(regname, FALSE); | 1601 |
1602 if (get_yank_register(regname, FALSE)) | |
1603 literally = TRUE; | |
1589 if (y_current->y_array == NULL) | 1604 if (y_current->y_array == NULL) |
1590 return FAIL; | 1605 return FAIL; |
1591 | 1606 |
1592 for (i = 0; i < y_current->y_size; ++i) | 1607 for (i = 0; i < y_current->y_size; ++i) |
1593 { | 1608 { |