summaryrefslogtreecommitdiff
path: root/src/os_win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os_win32.c')
-rw-r--r--src/os_win32.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/os_win32.c b/src/os_win32.c
index f5e283ef8..ef0b6cc0b 100644
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -1466,6 +1466,11 @@ mch_inchar(
#define TYPEAHEADLEN 20
static char_u typeahead[TYPEAHEADLEN]; /* previously typed bytes. */
static int typeaheadlen = 0;
+#ifdef FEAT_MBYTE
+ static char_u *rest = NULL; /* unconverted rest of previous read */
+ static int restlen = 0;
+ int unconverted;
+#endif
/* First use any typeahead that was kept because "buf" was too small. */
if (typeaheadlen > 0)
@@ -1569,6 +1574,33 @@ mch_inchar(
c = tgetch(&modifiers, &ch2);
+#ifdef FEAT_MBYTE
+ /* stolen from fill_input_buf() in ui.c */
+ if (rest != NULL)
+ {
+ /* Use remainder of previous call, starts with an invalid
+ * character that may become valid when reading more. */
+ if (restlen > TYPEAHEADLEN - typeaheadlen)
+ unconverted = TYPEAHEADLEN - typeaheadlen;
+ else
+ unconverted = restlen;
+ mch_memmove(typeahead + typeaheadlen, rest, unconverted);
+ if (unconverted == restlen)
+ {
+ vim_free(rest);
+ rest = NULL;
+ }
+ else
+ {
+ restlen -= unconverted;
+ mch_memmove(rest, rest + unconverted, restlen);
+ }
+ typeaheadlen += unconverted;
+ }
+ else
+ unconverted = 0;
+#endif
+
if (typebuf_changed(tb_change_cnt))
{
/* "buf" may be invalid now if a client put something in the
@@ -1604,8 +1636,12 @@ mch_inchar(
* when 'tenc' is set. */
if (input_conv.vc_type != CONV_NONE
&& (ch2 == NUL || c != K_NUL))
- n = convert_input(typeahead + typeaheadlen, n,
- TYPEAHEADLEN - typeaheadlen);
+ {
+ typeaheadlen -= unconverted;
+ n = convert_input_safe(typeahead + typeaheadlen,
+ n + unconverted, TYPEAHEADLEN - typeaheadlen,
+ rest == NULL ? &rest : NULL, &restlen);
+ }
#endif
/* Use the ALT key to set the 8th bit of the character