forked from aniani/vim
patch 9.0.1717: virtcol2col returns last byte of a multi-byte char
Problem: virtcol2col returns last byte of a multi-byte char Solution: Make it return the first byte for a multi-byte char closes: #12786 closes: #12799 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
committed by
Christian Brabandt
parent
15a0a0281a
commit
b209b86e66
21
src/move.c
21
src/move.c
@@ -1556,6 +1556,25 @@ f_screenpos(typval_T *argvars UNUSED, typval_T *rettv)
|
||||
dict_add_number(dict, "endcol", ecol);
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a virtual (screen) column to a character column. The first column
|
||||
* is one. For a multibyte character, the column number of the first byte is
|
||||
* returned.
|
||||
*/
|
||||
static int
|
||||
virtcol2col(win_T *wp, linenr_T lnum, int vcol)
|
||||
{
|
||||
int offset = vcol2col(wp, lnum, vcol);
|
||||
char_u *line = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
||||
char_u *p = line + offset;
|
||||
|
||||
// For a multibyte character, need to return the column number of the first
|
||||
// byte.
|
||||
MB_PTR_BACK(line, p);
|
||||
|
||||
return (int)(p - line + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* "virtcol2col({winid}, {lnum}, {col})" function
|
||||
*/
|
||||
@@ -1586,7 +1605,7 @@ f_virtcol2col(typval_T *argvars UNUSED, typval_T *rettv)
|
||||
if (error || screencol < 0)
|
||||
return;
|
||||
|
||||
rettv->vval.v_number = vcol2col(wp, lnum, screencol);
|
||||
rettv->vval.v_number = virtcol2col(wp, lnum, screencol);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user