diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-05-02 19:33:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 19:33:54 +0800 |
commit | c4627676f9a3bc88760c54bc6f1dc38904f064d2 (patch) | |
tree | 6c49387d7c1edcf808ab6f07d97e88fe9468c060 /src/nvim/eval/funcs.c | |
parent | d26943a6e185dea23077d41b4c81281e12be3997 (diff) | |
download | rneovim-c4627676f9a3bc88760c54bc6f1dc38904f064d2.tar.gz rneovim-c4627676f9a3bc88760c54bc6f1dc38904f064d2.tar.bz2 rneovim-c4627676f9a3bc88760c54bc6f1dc38904f064d2.zip |
vim-patch:9.1.0388: cursor() and getregion() don't handle v:maxcol well (#28602)
Problem: cursor() and getregion() don't handle v:maxcol well.
Solution: Add special handling for v:maxcol like setpos() does.
(zeertzjq)
closes: vim/vim#14698
https://github.com/vim/vim/commit/2ffdae79487cb7e323383eda9ae96c2e9d1625bd
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 8528168be1..b1ee33929c 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1185,9 +1185,10 @@ static void set_cursorpos(typval_T *argvars, typval_T *rettv, bool charcol) if (lnum > 0) { curwin->w_cursor.lnum = lnum; } - if (col > 0) { - curwin->w_cursor.col = col - 1; + if (col != MAXCOL && --col < 0) { + col = 0; } + curwin->w_cursor.col = col; curwin->w_cursor.coladd = coladd; // Make sure the cursor is in a valid position. @@ -2879,15 +2880,20 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) semsg(_(e_invalid_line_number_nr), p1.lnum); return; } - if (p1.col < 1 || p1.col > ml_get_buf_len(findbuf, p1.lnum) + 1) { + if (p1.col == MAXCOL) { + p1.col = ml_get_buf_len(findbuf, p1.lnum) + 1; + } else if (p1.col < 1 || p1.col > ml_get_buf_len(findbuf, p1.lnum) + 1) { semsg(_(e_invalid_column_number_nr), p1.col); return; } + if (p2.lnum < 1 || p2.lnum > findbuf->b_ml.ml_line_count) { semsg(_(e_invalid_line_number_nr), p2.lnum); return; } - if (p2.col < 1 || p2.col > ml_get_buf_len(findbuf, p2.lnum) + 1) { + if (p2.col == MAXCOL) { + p2.col = ml_get_buf_len(findbuf, p2.lnum) + 1; + } else if (p2.col < 1 || p2.col > ml_get_buf_len(findbuf, p2.lnum) + 1) { semsg(_(e_invalid_column_number_nr), p2.col); return; } |