summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-05-22 16:42:44 +0200
committerChristian Brabandt <cb@256bit.org>2024-05-22 16:42:44 +0200
commit52a6f348874778cf315b47d9e8b5f818f4b97277 (patch)
tree9445db2ad79338de8626f28b473892cc24ff189d /src/evalfunc.c
parent95ff39f8e3d5e16d4ef55f47d8f50da29df05f9e (diff)
patch 9.1.0430: getregionpos() doesn't handle one char selectionv9.1.0430
Problem: getregionpos() doesn't handle one char selection. Solution: Handle startspaces differently when is_oneChar is set. Also add a test for an exclusive charwise selection with multibyte chars (zeertzjq) closes: #14825 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 903205ad31..b65df5dd90 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -5793,7 +5793,6 @@ f_getregionpos(typval_T *argvars, typval_T *rettv)
for (lnum = p1.lnum; lnum <= p2.lnum; lnum++)
{
- struct block_def bd;
pos_T ret_p1, ret_p2;
if (region_type == MLINE)
@@ -5805,11 +5804,28 @@ f_getregionpos(typval_T *argvars, typval_T *rettv)
}
else
{
+ struct block_def bd;
+
if (region_type == MBLOCK)
block_prep(&oa, &bd, lnum, FALSE);
else
charwise_block_prep(p1, p2, &bd, lnum, inclusive);
- if (bd.startspaces > 0)
+
+ if (bd.is_oneChar) // selection entirely inside one char
+ {
+ if (region_type == MBLOCK)
+ {
+ ret_p1.col = bd.textcol;
+ ret_p1.coladd = bd.start_char_vcols
+ - (bd.start_vcol - oa.start_vcol);
+ }
+ else
+ {
+ ret_p1.col = p1.col + 1;
+ ret_p1.coladd = p1.coladd;
+ }
+ }
+ else if (bd.startspaces > 0)
{
ret_p1.col = bd.textcol;
ret_p1.coladd = bd.start_char_vcols - bd.startspaces;
@@ -5819,7 +5835,13 @@ f_getregionpos(typval_T *argvars, typval_T *rettv)
ret_p1.col = bd.textcol + 1;
ret_p1.coladd = 0;
}
- if (bd.endspaces > 0)
+
+ if (bd.is_oneChar) // selection entirely inside one char
+ {
+ ret_p2.col = ret_p1.col;
+ ret_p2.coladd = ret_p1.coladd + bd.startspaces;
+ }
+ else if (bd.endspaces > 0)
{
ret_p2.col = bd.textcol + bd.textlen + 1;
ret_p2.coladd = bd.endspaces;