Skip to content

Commit bc5020a

Browse files
committed
patch 8.1.0059: displayed digraph for "ga" wrong with 'encoding' "cp1251"
Problem: Displayed digraph for "ga" wrong with 'encoding' "cp1251". Solution: Convert from 'encoding' to "utf-8" if needed. (closes #3015)
1 parent bfa4246 commit bc5020a

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/digraph.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,14 +1979,37 @@ do_digraph(int c)
19791979
* If not found return NULL.
19801980
*/
19811981
char_u *
1982-
get_digraph_for_char(val)
1983-
int val;
1982+
get_digraph_for_char(int val_arg)
19841983
{
1984+
int val = val_arg;
19851985
int i;
19861986
int use_defaults;
19871987
digr_T *dp;
19881988
static char_u r[3];
19891989

1990+
#if defined(FEAT_MBYTE) && defined(USE_UNICODE_DIGRAPHS)
1991+
if (!enc_utf8)
1992+
{
1993+
char_u buf[6], *to;
1994+
vimconv_T vc;
1995+
1996+
// convert the character from 'encoding' to Unicode
1997+
i = mb_char2bytes(val, buf);
1998+
vc.vc_type = CONV_NONE;
1999+
if (convert_setup(&vc, p_enc, (char_u *)"utf-8") == OK)
2000+
{
2001+
vc.vc_fail = TRUE;
2002+
to = string_convert(&vc, buf, &i);
2003+
if (to != NULL)
2004+
{
2005+
val = utf_ptr2char(to);
2006+
vim_free(to);
2007+
}
2008+
(void)convert_setup(&vc, NULL, NULL);
2009+
}
2010+
}
2011+
#endif
2012+
19902013
for (use_defaults = 0; use_defaults <= 1; use_defaults++)
19912014
{
19922015
if (use_defaults == 0)

src/testdir/test_digraph.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,16 @@ func Test_show_digraph()
465465
bwipe!
466466
endfunc
467467

468+
func Test_show_digraph_cp1251()
469+
if !has('multi_byte')
470+
return
471+
endif
472+
new
473+
set encoding=cp1251
474+
call Put_Dig("='")
475+
call assert_equal("\n<\xfa> <|z> <M-z> 250, Hex fa, Oct 372, Digr ='", execute('ascii'))
476+
set encoding=utf-8
477+
bwipe!
478+
endfunc
479+
468480
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
59,
764766
/**/
765767
58,
766768
/**/

0 commit comments

Comments
 (0)