]> granicus.if.org Git - vim/commitdiff
patch 8.2.4734: getcharpos() may change a mark position v8.2.4734
authorBram Moolenaar <Bram@vim.org>
Mon, 11 Apr 2022 12:05:16 +0000 (13:05 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 11 Apr 2022 12:05:16 +0000 (13:05 +0100)
Problem:    getcharpos() may change a mark position.
Solution:   Copy the mark position. (closes #10148)

src/eval.c
src/testdir/test_cursor_func.vim
src/version.c

index b30577fecc168879563f91d0c0128169ba5b1b30..793a5263dd4de872f52dacdac6743ec0aee42236 100644 (file)
@@ -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;
index 7d21d847294773b253ae52be50f80c943468a8ca..1c26f6d35ef29114e2a77360bbe5969e9d64955a 100644 (file)
@@ -188,12 +188,12 @@ func Test_getcharpos()
   call assert_fails('call getcharpos({})', 'E731:')
   call assert_equal([0, 0, 0, 0], getcharpos(0))
   new
-  call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
+  call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678', ' │  x'])
 
   " Test for '.' and '$'
   normal 1G
   call assert_equal([0, 1, 1, 0], getcharpos('.'))
-  call assert_equal([0, 4, 1, 0], getcharpos('$'))
+  call assert_equal([0, 5, 1, 0], getcharpos('$'))
   normal 2G6l
   call assert_equal([0, 2, 7, 0], getcharpos('.'))
   normal 3G$
@@ -207,6 +207,12 @@ func Test_getcharpos()
   delmarks m
   call assert_equal([0, 0, 0, 0], getcharpos("'m"))
 
+  " Check mark does not move
+  normal 5Gfxma
+  call assert_equal([0, 5, 5, 0], getcharpos("'a"))
+  call assert_equal([0, 5, 5, 0], getcharpos("'a"))
+  call assert_equal([0, 5, 5, 0], getcharpos("'a"))
+
   " Test for the visual start column
   vnoremap <expr> <F3> SaveVisualStartCharPos()
   let g:VisualStartPos = []
index cf575d1a5b0409fe9ea8a0c68ab3f10b45083739..5e026de3d4628286d60775989808606ab4822ea0 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4734,
 /**/
     4733,
 /**/