aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-10-11 00:24:52 +0800
committerGitHub <noreply@github.com>2022-10-11 00:24:52 +0800
commit26c653718097955dc4dfbeb45ab602c8dbe9dea5 (patch)
tree9ae12e34472a4aa6dae4cfb381a0648705b1351d /src/nvim/eval.c
parent8781213f00a22e20abeb4282204e900db799f4b5 (diff)
parent62a0c9f8c24b9115155cd4551976353ace3e2c5e (diff)
downloadrneovim-26c653718097955dc4dfbeb45ab602c8dbe9dea5.tar.gz
rneovim-26c653718097955dc4dfbeb45ab602c8dbe9dea5.tar.bz2
rneovim-26c653718097955dc4dfbeb45ab602c8dbe9dea5.zip
Merge pull request #20574 from zeertzjq/vim-8.2.2184
vim-patch:8.2.{1465,2184,2670,2671},9.0.{0712,partial:0715}
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;