aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-10-10 21:38:24 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-10-10 23:54:51 +0800
commit249cb8345d6e2f9986ad1dfe42d9cde0f9ed7d6a (patch)
tree1528d4e5fce4292d14653fc9103350a0a207511a /src/nvim/eval.c
parent5c9f6bdd8c0486ccc3fd1b6b408e7ced90bdbc5a (diff)
downloadrneovim-249cb8345d6e2f9986ad1dfe42d9cde0f9ed7d6a.tar.gz
rneovim-249cb8345d6e2f9986ad1dfe42d9cde0f9ed7d6a.tar.bz2
rneovim-249cb8345d6e2f9986ad1dfe42d9cde0f9ed7d6a.zip
vim-patch:9.0.0712: wrong column when calling setcursorcharpos() with zero lnum
Problem: Wrong column when calling setcursorcharpos() with zero lnum. Solution: Set the line number before calling buf_charidx_to_byteidx(). (closes vim/vim#11329) https://github.com/vim/vim/commit/79f234499b6692cc16970b7455bc9b002242632f
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 6eaf3d1f5e..ebc60ea5c7 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -6454,11 +6454,14 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret
return NULL;
}
-/// Convert list in "arg" into a position and optional file number.
-/// When "fnump" is NULL there is no file number, only 3 items.
+/// Convert list in "arg" into position "posp" and optional file number "fnump".
+/// When "fnump" is NULL there is no file number, only 3 items: [lnum, col, off]
/// Note that the column is passed on as-is, the caller may want to decrement
/// it to use 1 for the first column.
///
+/// @param charcol if true, use the column as the character index instead of the
+/// byte index.
+///
/// @return FAIL when conversion is not possible, doesn't check the position for
/// validity.
int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool charcol)
@@ -6498,13 +6501,16 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool c
return FAIL;
}
// If character position is specified, then convert to byte position
+ // If the line number is zero use the cursor line.
if (charcol) {
// Get the text for the specified line in a loaded buffer
buf_T *buf = buflist_findnr(fnump == NULL ? curbuf->b_fnum : *fnump);
if (buf == NULL || buf->b_ml.ml_mfp == NULL) {
return FAIL;
}
- n = buf_charidx_to_byteidx(buf, posp->lnum, (int)n) + 1;
+ n = buf_charidx_to_byteidx(buf,
+ posp->lnum == 0 ? curwin->w_cursor.lnum : posp->lnum,
+ (int)n) + 1;
}
posp->col = (colnr_T)n;