mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:8.2.4734: getcharpos() may change a mark position (#18077)
Problem: getcharpos() may change a mark position.
Solution: Copy the mark position. (closes vim/vim#10148)
3caf1cce2b
This commit is contained in:
parent
f0d07dcb74
commit
356cff78ec
@ -7739,7 +7739,6 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret
|
|||||||
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
static pos_T pos;
|
static pos_T pos;
|
||||||
pos_T *pp;
|
|
||||||
|
|
||||||
// Argument can be [lnum, col, coladd].
|
// Argument can be [lnum, col, coladd].
|
||||||
if (tv->v_type == VAR_LIST) {
|
if (tv->v_type == VAR_LIST) {
|
||||||
@ -7799,34 +7798,32 @@ pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum, int *const ret
|
|||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (name[0] == '.') { // Cursor.
|
|
||||||
|
pos.lnum = 0;
|
||||||
|
if (name[0] == '.') {
|
||||||
|
// cursor
|
||||||
pos = curwin->w_cursor;
|
pos = curwin->w_cursor;
|
||||||
if (charcol) {
|
} else if (name[0] == 'v' && name[1] == NUL) {
|
||||||
pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
|
// Visual start
|
||||||
}
|
|
||||||
return &pos;
|
|
||||||
}
|
|
||||||
if (name[0] == 'v' && name[1] == NUL) { // Visual start.
|
|
||||||
if (VIsual_active) {
|
if (VIsual_active) {
|
||||||
pos = VIsual;
|
pos = VIsual;
|
||||||
} else {
|
} else {
|
||||||
pos = curwin->w_cursor;
|
pos = curwin->w_cursor;
|
||||||
}
|
}
|
||||||
|
} else if (name[0] == '\'') {
|
||||||
|
// mark
|
||||||
|
const pos_T *const pp = getmark_buf_fnum(curbuf, (uint8_t)name[1], false, ret_fnum);
|
||||||
|
if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pos = *pp;
|
||||||
|
}
|
||||||
|
if (pos.lnum != 0) {
|
||||||
if (charcol) {
|
if (charcol) {
|
||||||
pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
|
pos.col = buf_byteidx_to_charidx(curbuf, pos.lnum, pos.col);
|
||||||
}
|
}
|
||||||
return &pos;
|
return &pos;
|
||||||
}
|
}
|
||||||
if (name[0] == '\'') { // Mark.
|
|
||||||
pp = getmark_buf_fnum(curbuf, (uint8_t)name[1], false, ret_fnum);
|
|
||||||
if (pp == NULL || pp == (pos_T *)-1 || pp->lnum <= 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (charcol) {
|
|
||||||
pp->col = buf_byteidx_to_charidx(curbuf, pp->lnum, pp->col);
|
|
||||||
}
|
|
||||||
return pp;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos.coladd = 0;
|
pos.coladd = 0;
|
||||||
|
|
||||||
|
@ -140,12 +140,12 @@ func Test_getcharpos()
|
|||||||
call assert_fails('call getcharpos({})', 'E731:')
|
call assert_fails('call getcharpos({})', 'E731:')
|
||||||
call assert_equal([0, 0, 0, 0], getcharpos(0))
|
call assert_equal([0, 0, 0, 0], getcharpos(0))
|
||||||
new
|
new
|
||||||
call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678'])
|
call setline(1, ['', "01\tà4è678", 'Ⅵ', '012345678', ' │ x'])
|
||||||
|
|
||||||
" Test for '.' and '$'
|
" Test for '.' and '$'
|
||||||
normal 1G
|
normal 1G
|
||||||
call assert_equal([0, 1, 1, 0], getcharpos('.'))
|
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
|
normal 2G6l
|
||||||
call assert_equal([0, 2, 7, 0], getcharpos('.'))
|
call assert_equal([0, 2, 7, 0], getcharpos('.'))
|
||||||
normal 3G$
|
normal 3G$
|
||||||
@ -159,6 +159,12 @@ func Test_getcharpos()
|
|||||||
delmarks m
|
delmarks m
|
||||||
call assert_equal([0, 0, 0, 0], getcharpos("'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
|
" Test for the visual start column
|
||||||
vnoremap <expr> <F3> SaveVisualStartCharPos()
|
vnoremap <expr> <F3> SaveVisualStartCharPos()
|
||||||
let g:VisualStartPos = []
|
let g:VisualStartPos = []
|
||||||
|
Loading…
Reference in New Issue
Block a user