diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-04-11 13:05:16 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-11 13:05:16 +0100 |
commit | 3caf1cce2b85a8f24195d057f0ad63082543e99e (patch) | |
tree | 1a5639a48592a8b4f4880fe53f4c769a8a0e4d88 /src/eval.c | |
parent | 4232dff815db1a727cb1aea26783267d8bd731c3 (diff) | |
download | vim-git-3caf1cce2b85a8f24195d057f0ad63082543e99e.tar.gz |
patch 8.2.4734: getcharpos() may change a mark positionv8.2.4734
Problem: getcharpos() may change a mark position.
Solution: Copy the mark position. (closes #10148)
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/eval.c b/src/eval.c index b30577fec..793a5263d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -5636,34 +5636,35 @@ var2fpos( name = tv_get_string_chk(varp); if (name == NULL) return NULL; + + pos.lnum = 0; if (name[0] == '.' && (!in_vim9script() || name[1] == NUL)) { // cursor pos = curwin->w_cursor; - if (charcol) - pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); - return &pos; } - if (name[0] == 'v' && name[1] == NUL) // Visual start + else if (name[0] == 'v' && name[1] == NUL) { + // Visual start if (VIsual_active) pos = VIsual; else pos = curwin->w_cursor; - if (charcol) - pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); - return &pos; } - if (name[0] == '\'' && (!in_vim9script() + else if (name[0] == '\'' && (!in_vim9script() || (name[1] != NUL && name[2] == NUL))) { // mark pp = getmark_buf_fnum(curbuf, name[1], FALSE, fnum); if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) return NULL; + pos = *pp; + } + if (pos.lnum != 0) + { if (charcol) - pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col); - return pp; + pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col); + return &pos; } pos.coladd = 0; |