From afc2295c2201ae87bfbb42d5f5315ad0583ccabf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 24 May 2024 19:07:12 +0200 Subject: patch 9.1.0443: Can't use blockwise selection with width for getregion() Problem: Can't use a blockwise selection with a width for getregion(). Solution: Add support for blockwise selection with width like the return value of getregtype() or the "regtype" value of TextYankPost (zeertzjq). closes: #14842 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt --- src/evalfunc.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'src/evalfunc.c') diff --git a/src/evalfunc.c b/src/evalfunc.c index a1f8a8f8e2..b389085ed7 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -5492,12 +5492,13 @@ getregionpos( pos_T *p2, int *inclusive, int *region_type, - oparg_T *oa) + oparg_T *oap) { int fnum1 = -1, fnum2 = -1; char_u *type; buf_T *findbuf; char_u default_type[] = "v"; + int block_width = 0; int is_select_exclusive; int l; @@ -5533,8 +5534,17 @@ getregionpos( *region_type = MCHAR; else if (type[0] == 'V' && type[1] == NUL) *region_type = MLINE; - else if (type[0] == Ctrl_V && type[1] == NUL) + else if (type[0] == Ctrl_V) + { + char_u *p = type + 1; + + if (*p != NUL && ((block_width = getdigits(&p)) <= 0 || *p != NUL)) + { + semsg(_(e_invalid_value_for_argument_str_str), "type", type); + return FAIL; + } *region_type = MBLOCK; + } else { semsg(_(e_invalid_value_for_argument_str_str), "type", type); @@ -5608,16 +5618,18 @@ getregionpos( getvvcol(curwin, p1, &sc1, NULL, &ec1); getvvcol(curwin, p2, &sc2, NULL, &ec2); - oa->motion_type = MBLOCK; - oa->inclusive = TRUE; - oa->op_type = OP_NOP; - oa->start = *p1; - oa->end = *p2; - oa->start_vcol = MIN(sc1, sc2); - if (is_select_exclusive && ec1 < sc2 && 0 < sc2 && ec2 > ec1) - oa->end_vcol = sc2 - 1; + oap->motion_type = MBLOCK; + oap->inclusive = TRUE; + oap->op_type = OP_NOP; + oap->start = *p1; + oap->end = *p2; + oap->start_vcol = MIN(sc1, sc2); + if (block_width > 0) + oap->end_vcol = oap->start_vcol + block_width - 1; + else if (is_select_exclusive && ec1 < sc2 && 0 < sc2 && ec2 > ec1) + oap->end_vcol = sc2 - 1; else - oa->end_vcol = MAX(ec1, ec2); + oap->end_vcol = MAX(ec1, ec2); } // Include the trailing byte of a multi-byte char. -- cgit v1.2.3