diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-05-23 06:08:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-23 06:08:24 +0800 |
commit | 5cbd6d9b9f232a6ff22ae3a9af80075404226e4b (patch) | |
tree | c17a90a3c65fc89e09bb77547d55ab8d1e161c33 /src/nvim/eval/funcs.c | |
parent | 3d43bdc81e4e0a7acf60050f1b749429516d30fa (diff) | |
download | rneovim-5cbd6d9b9f232a6ff22ae3a9af80075404226e4b.tar.gz rneovim-5cbd6d9b9f232a6ff22ae3a9af80075404226e4b.tar.bz2 rneovim-5cbd6d9b9f232a6ff22ae3a9af80075404226e4b.zip |
vim-patch:9.1.0430: getregionpos() doesn't handle one char selection (#28924)
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: vim/vim#14825
https://github.com/vim/vim/commit/52a6f348874778cf315b47d9e8b5f818f4b97277
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 1d01f3ad98..7453bbb601 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -3041,7 +3041,6 @@ static void f_getregionpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr } for (linenr_T lnum = p1.lnum; lnum <= p2.lnum; lnum++) { - struct block_def bd; pos_T ret_p1, ret_p2; if (region_type == kMTLineWise) { @@ -3050,19 +3049,34 @@ static void f_getregionpos(typval_T *argvars, typval_T *rettv, EvalFuncData fptr ret_p2.col = MAXCOL; ret_p2.coladd = 0; } else { + struct block_def bd; + if (region_type == kMTBlockWise) { 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 == kMTBlockWise) { + 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; } else { 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; } else { |