From f6b876ef1f4c1621dc4822ace7673e45dd30ea0b 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. Backport of changeset 7171:d07ee885f2dd, but translated to C++11. --- 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 ec78479b9..8d061205a 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -2284,7 +2284,18 @@ ptrdiff_t ScintillaCocoa::InsertText(NSString *input) { 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 sv = encoded; + while (sv.length()) { + const unsigned char leadByte = sv[0]; + const unsigned int bytesInCharacter = UTF8BytesOfLead[leadByte]; + AddCharUTF(sv.c_str(), bytesInCharacter, false); + sv = sv.substr(bytesInCharacter, sv.length()); + } + } else { + AddCharUTF(encoded.c_str(), static_cast(encoded.length()), false); + } } return encoded.length(); } -- cgit v1.2.3