aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2019-06-24 08:58:19 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2019-06-24 08:58:19 +1000
commitf4ad82650d5458ae3ecece6c0b71b3718bd0a9af (patch)
tree1725836b4c150aa0780f3ee50ec8b213cd8ce656
parent42a1e67cb346d2ce4667eb7bb15d72ffe15ebdc3 (diff)
downloadscintilla-mirror-f4ad82650d5458ae3ecece6c0b71b3718bd0a9af.tar.gz
For encodings other than UTF-8, split input up into characters before calling
InsertCharacter.
-rw-r--r--cocoa/ScintillaCocoa.mm45
1 files changed, 29 insertions, 16 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 0f1a53e17..0ce912f54 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -2176,25 +2176,38 @@ bool ScintillaCocoa::KeyboardInput(NSEvent *event) {
* Used to insert already processed text provided by the Cocoa text input system.
*/
ptrdiff_t ScintillaCocoa::InsertText(NSString *input) {
- CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(),
- vs.styles[STYLE_DEFAULT].characterSet);
- std::string encoded = EncodedBytesString((__bridge CFStringRef)input, encoding);
-
- if (encoded.length() > 0) {
- 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];
- InsertCharacter(sv.substr(0, bytesInCharacter));
- sv.remove_prefix(bytesInCharacter);
- }
- } else {
+ if ([input length] == 0) {
+ return 0;
+ }
+
+ // There may be multiple characters in input so loop over them
+ if (IsUnicodeMode()) {
+ // There may be non-BMP characters as 2 elements in NSString so
+ // convert to UTF-8 and use UTF8BytesOfLead.
+ std::string encoded = EncodedBytesString((__bridge CFStringRef)input,
+ kCFStringEncodingUTF8);
+ std::string_view sv = encoded;
+ while (sv.length()) {
+ const unsigned char leadByte = sv[0];
+ const unsigned int bytesInCharacter = UTF8BytesOfLead[leadByte];
+ InsertCharacter(sv.substr(0, bytesInCharacter));
+ sv.remove_prefix(bytesInCharacter);
+ }
+ return encoded.length();
+ } else {
+ const CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(),
+ vs.styles[STYLE_DEFAULT].characterSet);
+ ptrdiff_t lengthInserted = 0;
+ for (NSInteger i = 0; i < [input length]; i++) {
+ NSString *character = [input substringWithRange:NSMakeRange(i, 1)];
+ std::string encoded = EncodedBytesString((__bridge CFStringRef)character,
+ encoding);
+ lengthInserted += encoded.length();
InsertCharacter(encoded);
}
+
+ return lengthInserted;
}
- return encoded.length();
}
//--------------------------------------------------------------------------------------------------