diff options
Diffstat (limited to 'platform/osx/display_server_osx.mm')
-rw-r--r-- | platform/osx/display_server_osx.mm | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 1ad7117b39..3025210195 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -701,8 +701,6 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; characters = (NSString *)aString; } - NSUInteger i, length = [characters length]; - NSCharacterSet *ctrlChars = [NSCharacterSet controlCharacterSet]; NSCharacterSet *wsnlChars = [NSCharacterSet whitespaceAndNewlineCharacterSet]; if ([characters rangeOfCharacterFromSet:ctrlChars].length && [characters rangeOfCharacterFromSet:wsnlChars].length == 0) { @@ -712,8 +710,15 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; return; } - for (i = 0; i < length; i++) { - const unichar codepoint = [characters characterAtIndex:i]; + Char16String text; + text.resize([characters length] + 1); + [characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])]; + + String u32text; + u32text.parse_utf16(text.ptr(), text.length()); + + for (int i = 0; i < u32text.length(); i++) { + const char32_t codepoint = u32text[i]; if ((codepoint & 0xFF00) == 0xF700) { continue; } @@ -1315,7 +1320,16 @@ static int remapKey(unsigned int key, unsigned int state) { if (!wd.im_active && length > 0 && keycode_has_unicode(remapKey([event keyCode], [event modifierFlags]))) { // Fallback unicode character handler used if IME is not active - for (NSUInteger i = 0; i < length; i++) { + Char16String text; + text.resize([characters length] + 1); + [characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])]; + + String u32text; + u32text.parse_utf16(text.ptr(), text.length()); + + for (int i = 0; i < u32text.length(); i++) { + const char32_t codepoint = u32text[i]; + DisplayServerOSX::KeyEvent ke; ke.window_id = window_id; @@ -1325,7 +1339,7 @@ static int remapKey(unsigned int key, unsigned int state) { ke.keycode = remapKey([event keyCode], [event modifierFlags]); ke.physical_keycode = translateKey([event keyCode]); ke.raw = true; - ke.unicode = [characters characterAtIndex:i]; + ke.unicode = codepoint; _push_to_key_event_buffer(ke); } @@ -1417,7 +1431,15 @@ static int remapKey(unsigned int key, unsigned int state) { // Fallback unicode character handler used if IME is not active if (!wd.im_active && length > 0 && keycode_has_unicode(remapKey([event keyCode], [event modifierFlags]))) { - for (NSUInteger i = 0; i < length; i++) { + Char16String text; + text.resize([characters length] + 1); + [characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])]; + + String u32text; + u32text.parse_utf16(text.ptr(), text.length()); + + for (int i = 0; i < u32text.length(); i++) { + const char32_t codepoint = u32text[i]; DisplayServerOSX::KeyEvent ke; ke.window_id = window_id; @@ -1427,7 +1449,7 @@ static int remapKey(unsigned int key, unsigned int state) { ke.keycode = remapKey([event keyCode], [event modifierFlags]); ke.physical_keycode = translateKey([event keyCode]); ke.raw = true; - ke.unicode = [characters characterAtIndex:i]; + ke.unicode = codepoint; _push_to_key_event_buffer(ke); } |