summaryrefslogtreecommitdiff
path: root/src/gui_w48.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui_w48.c')
-rw-r--r--src/gui_w48.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/gui_w48.c b/src/gui_w48.c
index cfbbbc00b..42cf91fd6 100644
--- a/src/gui_w48.c
+++ b/src/gui_w48.c
@@ -486,10 +486,11 @@ _OnDeadChar(
/*
* Convert Unicode character "ch" to bytes in "string[slen]".
+ * When "had_alt" is TRUE the ALT key was included in "ch".
* Return the length.
*/
static int
-char_to_string(int ch, char_u *string, int slen)
+char_to_string(int ch, char_u *string, int slen, int had_alt)
{
int len;
int i;
@@ -522,8 +523,22 @@ char_to_string(int ch, char_u *string, int slen)
* "enc_codepage" is non-zero use the standard Win32 function,
* otherwise use our own conversion function (e.g., for UTF-8). */
if (enc_codepage > 0)
+ {
len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
string, slen, 0, NULL);
+ /* If we had included the ALT key into the character but now the
+ * upper bit is no longer set, that probably means the conversion
+ * failed. Convert the original character and set the upper bit
+ * afterwards. */
+ if (had_alt && len == 1 && ch >= 0x80 && string[0] < 0x80)
+ {
+ wstring[0] = ch & 0x7f;
+ len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
+ string, slen, 0, NULL);
+ if (len == 1) /* safety check */
+ string[0] |= 0x80;
+ }
+ }
else
{
len = 1;
@@ -573,7 +588,7 @@ _OnChar(
char_u string[40];
int len = 0;
- len = char_to_string(ch, string, 40);
+ len = char_to_string(ch, string, 40, FALSE);
if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
{
trash_input_buf();
@@ -640,7 +655,7 @@ _OnSysChar(
{
/* Although the documentation isn't clear about it, we assume "ch" is
* a Unicode character. */
- len += char_to_string(ch, string + len, 40 - len);
+ len += char_to_string(ch, string + len, 40 - len, TRUE);
}
add_to_input_buf(string, len);
@@ -1775,7 +1790,7 @@ process_message(void)
int len;
/* Handle "key" as a Unicode character. */
- len = char_to_string(key, string, 40);
+ len = char_to_string(key, string, 40, FALSE);
add_to_input_buf(string, len);
}
break;