vim-patch:9.1.0443: Can't use blockwise selection with width for getregion() (#28985)

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: vim/vim#14842

afc2295c22
This commit is contained in:
zeertzjq
2024-05-25 05:19:46 +08:00
committed by GitHub
parent 28c04948a1
commit 06347a64ca
5 changed files with 96 additions and 48 deletions

View File

@@ -2824,7 +2824,7 @@ static char *block_def2str(struct block_def *bd)
}
static int getregionpos(typval_T *argvars, typval_T *rettv, pos_T *p1, pos_T *p2,
bool *const inclusive, MotionType *region_type, oparg_T *oa)
bool *const inclusive, MotionType *region_type, oparg_T *oap)
FUNC_ATTR_NONNULL_ALL
{
tv_list_alloc_ret(rettv, kListLenMayKnow);
@@ -2858,11 +2858,17 @@ static int getregionpos(typval_T *argvars, typval_T *rettv, pos_T *p1, pos_T *p2
type = default_type;
}
int block_width = 0;
if (type[0] == 'v' && type[1] == NUL) {
*region_type = kMTCharWise;
} else if (type[0] == 'V' && type[1] == NUL) {
*region_type = kMTLineWise;
} else if (type[0] == Ctrl_V && type[1] == NUL) {
} else if (type[0] == Ctrl_V) {
char *p = type + 1;
if (*p != NUL && ((block_width = getdigits_int(&p, false, 0)) <= 0 || *p != NUL)) {
semsg(_(e_invargNval), "type", type);
return FAIL;
}
*region_type = kMTBlockWise;
} else {
semsg(_(e_invargNval), "type", type);
@@ -2926,16 +2932,18 @@ static int getregionpos(typval_T *argvars, typval_T *rettv, pos_T *p1, pos_T *p2
colnr_T sc1, ec1, sc2, ec2;
getvvcol(curwin, p1, &sc1, NULL, &ec1);
getvvcol(curwin, p2, &sc2, NULL, &ec2);
oa->motion_type = kMTBlockWise;
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 = kMTBlockWise;
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);
}
}