Mercurial > vim
diff 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 |
line wrap: on
line diff
--- a/src/register.c +++ b/src/register.c @@ -32,7 +32,7 @@ static int stuff_yank(int, char_u *); static void put_reedit_in_typebuf(int silent); static int put_in_typebuf(char_u *s, int esc, int colon, int silent); -static int yank_copy_line(struct block_def *bd, long y_idx); +static int yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space); #ifdef FEAT_CLIPBOARD static void copy_yank_reg(yankreg_T *reg); #endif @@ -1208,20 +1208,20 @@ op_yank(oparg_T *oap, int deleting, int { case MBLOCK: block_prep(oap, &bd, lnum, FALSE); - if (yank_copy_line(&bd, y_idx) == FAIL) + if (yank_copy_line(&bd, y_idx, oap->excl_tr_ws) == FAIL) goto fail; break; case MLINE: if ((y_current->y_array[y_idx] = - vim_strsave(ml_get(lnum))) == NULL) + vim_strsave(ml_get(lnum))) == NULL) goto fail; break; case MCHAR: { colnr_T startcol = 0, endcol = MAXCOL; - int is_oneChar = FALSE; + int is_oneChar = FALSE; colnr_T cs, ce; p = ml_get(lnum); @@ -1282,7 +1282,7 @@ op_yank(oparg_T *oap, int deleting, int else bd.textlen = endcol - startcol + oap->inclusive; bd.textstart = p + startcol; - if (yank_copy_line(&bd, y_idx) == FAIL) + if (yank_copy_line(&bd, y_idx, FALSE) == FAIL) goto fail; break; } @@ -1443,8 +1443,12 @@ fail: // free the allocated lines return FAIL; } +/* + * Copy a block range into a register. + * If "exclude_trailing_space" is set, do not copy trailing whitespaces. + */ static int -yank_copy_line(struct block_def *bd, long y_idx) +yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space) { char_u *pnew; @@ -1458,6 +1462,16 @@ yank_copy_line(struct block_def *bd, lon pnew += bd->textlen; vim_memset(pnew, ' ', (size_t)bd->endspaces); pnew += bd->endspaces; + if (exclude_trailing_space) + { + int s = bd->textlen + bd->endspaces; + + while (VIM_ISWHITE(*(bd->textstart + s - 1)) && s > 0) + { + s = s - (*mb_head_off)(bd->textstart, bd->textstart + s - 1) - 1; + pnew--; + } + } *pnew = NUL; return OK; }