From e6010657a470a0575a7be23e730b6e9867f9f26c Mon Sep 17 00:00:00 2001 From: Neil Hodgson Date: Tue, 20 Nov 2018 12:14:54 +1100 Subject: Bug [#2061]. Fix a crash that occurred when entering a dead key diacritic then a character that can not take that diacritic, such as option+e (acute accent) followed by g. --- cocoa/ScintillaCocoa.mm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'cocoa') diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 1338a66fa..9a7125023 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -2179,7 +2179,18 @@ ptrdiff_t ScintillaCocoa::InsertText(NSString *input) { std::string encoded = EncodedBytesString((__bridge CFStringRef)input, encoding); if (encoded.length() > 0) { - AddCharUTF(encoded.c_str(), static_cast(encoded.length()), false); + if (encoding == kCFStringEncodingUTF8) { + // There may be multiple characters in input so loop over them + std::string_view sv = encoded; + while (sv.length()) { + const unsigned char leadByte = sv[0]; + const unsigned int bytesInCharacter = UTF8BytesOfLead[leadByte]; + AddCharUTF(sv.data(), bytesInCharacter, false); + sv.remove_prefix(bytesInCharacter); + } + } else { + AddCharUTF(encoded.c_str(), static_cast(encoded.length()), false); + } } return encoded.length(); } -- cgit v1.2.3