diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-10-10 12:42:57 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-10-10 12:42:57 +0100 |
commit | 79f234499b6692cc16970b7455bc9b002242632f (patch) | |
tree | fdf04b2e144fd6c2106f20f50eaacc2c06ed19bb /src/evalfunc.c | |
parent | 084f2620ec7d08d6043de30436197c002fffe3ec (diff) | |
download | vim-git-79f234499b6692cc16970b7455bc9b002242632f.tar.gz |
patch 9.0.0712: wrong column when calling setcursorcharpos() with zero lnumv9.0.0712
Problem: Wrong column when calling setcursorcharpos() with zero lnum.
Solution: Set the line number before calling buf_charidx_to_byteidx().
(closes #11329)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r-- | src/evalfunc.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index a2a5296ae..07ea31178 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -3545,7 +3545,7 @@ f_copy(typval_T *argvars, typval_T *rettv) static void set_cursorpos(typval_T *argvars, typval_T *rettv, int charcol) { - long line, col; + long lnum, col; long coladd = 0; int set_curswant = TRUE; @@ -3567,7 +3567,7 @@ set_cursorpos(typval_T *argvars, typval_T *rettv, int charcol) emsg(_(e_invalid_argument)); return; } - line = pos.lnum; + lnum = pos.lnum; col = pos.col; coladd = pos.coladd; if (curswant >= 0) @@ -3576,17 +3576,19 @@ set_cursorpos(typval_T *argvars, typval_T *rettv, int charcol) set_curswant = FALSE; } } - else if ((argvars[0].v_type == VAR_NUMBER || - argvars[0].v_type == VAR_STRING) - && (argvars[1].v_type == VAR_NUMBER || - argvars[1].v_type == VAR_STRING)) + else if ((argvars[0].v_type == VAR_NUMBER + || argvars[0].v_type == VAR_STRING) + && (argvars[1].v_type == VAR_NUMBER + || argvars[1].v_type == VAR_STRING)) { - line = tv_get_lnum(argvars); - if (line < 0) + lnum = tv_get_lnum(argvars); + if (lnum < 0) semsg(_(e_invalid_argument_str), tv_get_string(&argvars[0])); + else if (lnum == 0) + lnum = curwin->w_cursor.lnum; col = (long)tv_get_number_chk(&argvars[1], NULL); if (charcol) - col = buf_charidx_to_byteidx(curbuf, line, col) + 1; + col = buf_charidx_to_byteidx(curbuf, lnum, col) + 1; if (argvars[2].v_type != VAR_UNKNOWN) coladd = (long)tv_get_number_chk(&argvars[2], NULL); } @@ -3595,10 +3597,10 @@ set_cursorpos(typval_T *argvars, typval_T *rettv, int charcol) emsg(_(e_invalid_argument)); return; } - if (line < 0 || col < 0 || coladd < 0) + if (lnum < 0 || col < 0 || coladd < 0) return; // type error; errmsg already given - if (line > 0) - curwin->w_cursor.lnum = line; + if (lnum > 0) + curwin->w_cursor.lnum = lnum; if (col > 0) curwin->w_cursor.col = col - 1; curwin->w_cursor.coladd = coladd; |