comparison src/register.c @ 24866:f1121eb17e14 v8.2.2971

patch 8.2.2971: cannot yank a block without trailing spaces Commit: https://github.com/vim/vim/commit/544a38e44db0f25ec4fa7a2a4666cf28a2336f33 Author: Christian Brabandt <cb@256bit.org> Date: Thu Jun 10 19:39:11 2021 +0200 patch 8.2.2971: cannot yank a block without trailing spaces Problem: Cannot yank a block without trailing spaces. Solution: Add the "zy" command. (Christian Brabandt, closes https://github.com/vim/vim/issues/8292)
author Bram Moolenaar <Bram@vim.org>
date Thu, 10 Jun 2021 19:45:02 +0200
parents fd245e5d4585
children dc3d45d9a4a8
comparison
equal deleted inserted replaced
24865:8dfff43cdcb8 24866:f1121eb17e14
30 30
31 static int stuff_yank(int, char_u *); 31 static int stuff_yank(int, char_u *);
32 static void put_reedit_in_typebuf(int silent); 32 static void put_reedit_in_typebuf(int silent);
33 static int put_in_typebuf(char_u *s, int esc, int colon, 33 static int put_in_typebuf(char_u *s, int esc, int colon,
34 int silent); 34 int silent);
35 static int yank_copy_line(struct block_def *bd, long y_idx); 35 static int yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space);
36 #ifdef FEAT_CLIPBOARD 36 #ifdef FEAT_CLIPBOARD
37 static void copy_yank_reg(yankreg_T *reg); 37 static void copy_yank_reg(yankreg_T *reg);
38 #endif 38 #endif
39 static void dis_msg(char_u *p, int skip_esc); 39 static void dis_msg(char_u *p, int skip_esc);
40 40
1206 { 1206 {
1207 switch (y_current->y_type) 1207 switch (y_current->y_type)
1208 { 1208 {
1209 case MBLOCK: 1209 case MBLOCK:
1210 block_prep(oap, &bd, lnum, FALSE); 1210 block_prep(oap, &bd, lnum, FALSE);
1211 if (yank_copy_line(&bd, y_idx) == FAIL) 1211 if (yank_copy_line(&bd, y_idx, oap->excl_tr_ws) == FAIL)
1212 goto fail; 1212 goto fail;
1213 break; 1213 break;
1214 1214
1215 case MLINE: 1215 case MLINE:
1216 if ((y_current->y_array[y_idx] = 1216 if ((y_current->y_array[y_idx] =
1217 vim_strsave(ml_get(lnum))) == NULL) 1217 vim_strsave(ml_get(lnum))) == NULL)
1218 goto fail; 1218 goto fail;
1219 break; 1219 break;
1220 1220
1221 case MCHAR: 1221 case MCHAR:
1222 { 1222 {
1223 colnr_T startcol = 0, endcol = MAXCOL; 1223 colnr_T startcol = 0, endcol = MAXCOL;
1224 int is_oneChar = FALSE; 1224 int is_oneChar = FALSE;
1225 colnr_T cs, ce; 1225 colnr_T cs, ce;
1226 1226
1227 p = ml_get(lnum); 1227 p = ml_get(lnum);
1228 bd.startspaces = 0; 1228 bd.startspaces = 0;
1229 bd.endspaces = 0; 1229 bd.endspaces = 0;
1280 if (startcol > endcol || is_oneChar) 1280 if (startcol > endcol || is_oneChar)
1281 bd.textlen = 0; 1281 bd.textlen = 0;
1282 else 1282 else
1283 bd.textlen = endcol - startcol + oap->inclusive; 1283 bd.textlen = endcol - startcol + oap->inclusive;
1284 bd.textstart = p + startcol; 1284 bd.textstart = p + startcol;
1285 if (yank_copy_line(&bd, y_idx) == FAIL) 1285 if (yank_copy_line(&bd, y_idx, FALSE) == FAIL)
1286 goto fail; 1286 goto fail;
1287 break; 1287 break;
1288 } 1288 }
1289 // NOTREACHED 1289 // NOTREACHED
1290 } 1290 }
1441 free_yank(y_idx + 1); 1441 free_yank(y_idx + 1);
1442 y_current = curr; 1442 y_current = curr;
1443 return FAIL; 1443 return FAIL;
1444 } 1444 }
1445 1445
1446 /*
1447 * Copy a block range into a register.
1448 * If "exclude_trailing_space" is set, do not copy trailing whitespaces.
1449 */
1446 static int 1450 static int
1447 yank_copy_line(struct block_def *bd, long y_idx) 1451 yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space)
1448 { 1452 {
1449 char_u *pnew; 1453 char_u *pnew;
1450 1454
1451 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) 1455 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1))
1452 == NULL) 1456 == NULL)
1456 pnew += bd->startspaces; 1460 pnew += bd->startspaces;
1457 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); 1461 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen);
1458 pnew += bd->textlen; 1462 pnew += bd->textlen;
1459 vim_memset(pnew, ' ', (size_t)bd->endspaces); 1463 vim_memset(pnew, ' ', (size_t)bd->endspaces);
1460 pnew += bd->endspaces; 1464 pnew += bd->endspaces;
1465 if (exclude_trailing_space)
1466 {
1467 int s = bd->textlen + bd->endspaces;
1468
1469 while (VIM_ISWHITE(*(bd->textstart + s - 1)) && s > 0)
1470 {
1471 s = s - (*mb_head_off)(bd->textstart, bd->textstart + s - 1) - 1;
1472 pnew--;
1473 }
1474 }
1461 *pnew = NUL; 1475 *pnew = NUL;
1462 return OK; 1476 return OK;
1463 } 1477 }
1464 1478
1465 #ifdef FEAT_CLIPBOARD 1479 #ifdef FEAT_CLIPBOARD