comparison src/edit.c @ 10640:27be410d6d29 v8.0.0210

patch 8.0.0210: no support for bracketed paste commit https://github.com/vim/vim/commit/ec2da36ca48b40c0654b32a8d2c9f52e796daa5e Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 21 20:04:22 2017 +0100 patch 8.0.0210: no support for bracketed paste Problem: Vim does not support bracketed paste, as implemented by xterm and other terminals. Solution: Add t_BE, t_BD, t_PS and t_PE.
author Christian Brabandt <cb@256bit.org>
date Sat, 21 Jan 2017 20:15:04 +0100
parents 3db97def0f35
children 75c324ab1270
comparison
equal deleted inserted replaced
10639:9b3141c5aa1b 10640:27be410d6d29
307 * edit(): Start inserting text. 307 * edit(): Start inserting text.
308 * 308 *
309 * "cmdchar" can be: 309 * "cmdchar" can be:
310 * 'i' normal insert command 310 * 'i' normal insert command
311 * 'a' normal append command 311 * 'a' normal append command
312 * K_PS bracketed paste
312 * 'R' replace command 313 * 'R' replace command
313 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo, 314 * 'r' "r<CR>" command: insert one <CR>. Note: count can be > 1, for redo,
314 * but still only one <CR> is inserted. The <Esc> is not used for redo. 315 * but still only one <CR> is inserted. The <Esc> is not used for redo.
315 * 'g' "gI" command. 316 * 'g' "gI" command.
316 * 'V' "gR" command for Virtual Replace mode. 317 * 'V' "gR" command for Virtual Replace mode.
780 /* After using CTRL-G U the next cursor key will not break undo. */ 781 /* After using CTRL-G U the next cursor key will not break undo. */
781 if (dont_sync_undo == MAYBE) 782 if (dont_sync_undo == MAYBE)
782 dont_sync_undo = TRUE; 783 dont_sync_undo = TRUE;
783 else 784 else
784 dont_sync_undo = FALSE; 785 dont_sync_undo = FALSE;
785 do 786 if (cmdchar == K_PS)
786 { 787 /* Got here from normal mode when bracketed paste started. */
787 c = safe_vgetc(); 788 c = K_PS;
788 } while (c == K_IGNORE); 789 else
790 do
791 {
792 c = safe_vgetc();
793 } while (c == K_IGNORE);
789 794
790 #ifdef FEAT_AUTOCMD 795 #ifdef FEAT_AUTOCMD
791 /* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */ 796 /* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
792 did_cursorhold = TRUE; 797 did_cursorhold = TRUE;
793 #endif 798 #endif
1191 1196
1192 case K_MOUSERIGHT: /* Scroll wheel right */ 1197 case K_MOUSERIGHT: /* Scroll wheel right */
1193 ins_mousescroll(MSCR_RIGHT); 1198 ins_mousescroll(MSCR_RIGHT);
1194 break; 1199 break;
1195 #endif 1200 #endif
1201 case K_PS:
1202 bracketed_paste(PASTE_INSERT, FALSE, NULL);
1203 if (cmdchar == K_PS)
1204 /* invoked from normal mode, bail out */
1205 goto doESCkey;
1206 break;
1207 case K_PE:
1208 /* Got K_PE without K_PS, ignore. */
1209 break;
1210
1196 #ifdef FEAT_GUI_TABLINE 1211 #ifdef FEAT_GUI_TABLINE
1197 case K_TABLINE: 1212 case K_TABLINE:
1198 case K_TABMENU: 1213 case K_TABMENU:
1199 ins_tabline(c); 1214 ins_tabline(c);
1200 break; 1215 break;
9422 # endif 9437 # endif
9423 } 9438 }
9424 } 9439 }
9425 #endif 9440 #endif
9426 9441
9442 /*
9443 * Handle receiving P_PS: start paste mode. Inserts the following text up to
9444 * P_PE literally.
9445 * When "drop" is TRUE then consume the text and drop it.
9446 */
9447 int
9448 bracketed_paste(paste_mode_T mode, int drop, garray_T *gap)
9449 {
9450 int c;
9451 char_u buf[NUMBUFLEN + MB_MAXBYTES];
9452 int idx = 0;
9453 char_u *end = find_termcode((char_u *)"PE");
9454 int ret_char = -1;
9455 int save_allow_keys = allow_keys;
9456
9457 /* If the end code is too long we can't detect it, read everything. */
9458 if (STRLEN(end) >= NUMBUFLEN)
9459 end = NULL;
9460 ++no_mapping;
9461 allow_keys = 0;
9462 for (;;)
9463 {
9464 /* When the end is not defined read everything. */
9465 if (end == NULL && vpeekc() == NUL)
9466 break;
9467 c = plain_vgetc();
9468 #ifdef FEAT_MBYTE
9469 if (has_mbyte)
9470 idx += (*mb_char2bytes)(c, buf + idx);
9471 else
9472 #endif
9473 buf[idx++] = c;
9474 buf[idx] = NUL;
9475 if (end != NUL && STRNCMP(buf, end, idx) == 0)
9476 {
9477 if (end[idx] == NUL)
9478 break; /* Found the end of paste code. */
9479 continue;
9480 }
9481 if (!drop)
9482 {
9483 switch (mode)
9484 {
9485 case PASTE_CMDLINE:
9486 put_on_cmdline(buf, idx, TRUE);
9487 break;
9488
9489 case PASTE_EX:
9490 if (gap != NULL && ga_grow(gap, idx) == OK)
9491 {
9492 mch_memmove((char *)gap->ga_data + gap->ga_len,
9493 buf, (size_t)idx);
9494 gap->ga_len += idx;
9495 }
9496 break;
9497
9498 case PASTE_INSERT:
9499 if (stop_arrow() == OK)
9500 {
9501 ins_char_bytes(buf, idx);
9502 AppendToRedobuffLit(buf, idx);
9503 }
9504 break;
9505
9506 case PASTE_ONE_CHAR:
9507 if (ret_char == -1)
9508 {
9509 #ifdef FEAT_MBYTE
9510 if (has_mbyte)
9511 ret_char = (*mb_ptr2char)(buf);
9512 else
9513 #endif
9514 ret_char = buf[0];
9515 }
9516 break;
9517 }
9518 }
9519 idx = 0;
9520 }
9521 --no_mapping;
9522 allow_keys = save_allow_keys;
9523
9524 return ret_char;
9525 }
9526
9427 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) 9527 #if defined(FEAT_GUI_TABLINE) || defined(PROTO)
9428 static void 9528 static void
9429 ins_tabline(int c) 9529 ins_tabline(int c)
9430 { 9530 {
9431 /* We will be leaving the current window, unless closing another tab. */ 9531 /* We will be leaving the current window, unless closing another tab. */