Skip to content
Snippets Groups Projects
Commit 6d88419c authored by George Nachman's avatar George Nachman
Browse files

Ensure that, when pasting chunks, a surrogate pair does not get cut in half. Issue 5040

parent 8db2ff42
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -248,6 +248,9 @@ int decode_utf8_char(const unsigned char * restrict datap,
// Contains only digits?
- (BOOL)isNumeric;
 
// Modify the range's endpoint to not sever a surrogate pair.
- (NSRange)makeRangeSafe:(NSRange)range;
@end
 
@interface NSMutableString (iTerm)
Loading
Loading
Loading
Loading
@@ -1615,6 +1615,21 @@ static TECObjectRef CreateTECConverterForUTF8Variants(TextEncodingVariant varian
return range.location == NSNotFound;
}
 
- (NSRange)makeRangeSafe:(NSRange)range {
if (range.location == NSNotFound || range.length == 0) {
return range;
}
unichar lastCharacter = [self characterAtIndex:NSMaxRange(range) - 1];
if (CFStringIsSurrogateHighCharacter(lastCharacter)) {
if (NSMaxRange(range) == self.length) {
range.length -= 1;
} else {
range.length += 1;
}
}
return range;
}
@end
 
@implementation NSMutableString (iTerm)
Loading
Loading
Loading
Loading
@@ -394,6 +394,7 @@ const int kNumberOfSpacesPerTabNoConversion = -1;
block = YES;
}
}
range = [_buffer makeRangeSafe:range];
[_delegate pasteHelperWriteString:[_buffer substringWithRange:range]];
}
[_buffer replaceCharactersInRange:range withString:@""];
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment