summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-10-10 12:42:57 +0100
committerBram Moolenaar <Bram@vim.org>2022-10-10 12:42:57 +0100
commit79f234499b6692cc16970b7455bc9b002242632f (patch)
treefdf04b2e144fd6c2106f20f50eaacc2c06ed19bb /src/eval.c
parent084f2620ec7d08d6043de30436197c002fffe3ec (diff)
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/eval.c')
-rw-r--r--src/eval.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c
index c37765fd89..1652fcb4ae 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -6023,10 +6023,12 @@ var2fpos(
}
/*
- * 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 "psop" 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.
+ * If "charcol" is 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.
*/
@@ -6069,6 +6071,7 @@ list2fpos(
if (n < 0)
return FAIL;
// If character position is specified, then convert to byte position
+ // If the line number is zero use the cursor line.
if (charcol)
{
buf_T *buf;
@@ -6078,7 +6081,8 @@ list2fpos(
if (buf == NULL || buf->b_ml.ml_mfp == NULL)
return FAIL;
- n = buf_charidx_to_byteidx(buf, posp->lnum, n) + 1;
+ n = buf_charidx_to_byteidx(buf,
+ posp->lnum == 0 ? curwin->w_cursor.lnum : posp->lnum, n) + 1;
}
posp->col = n;