Skip to content
Snippets Groups Projects
Commit aaae079f 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 73f768a9
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -230,6 +230,12 @@ int decode_utf8_char(const unsigned char * restrict datap,
// Returns a person's surname.
- (NSString *)surname;
 
// 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
@@ -1549,6 +1549,30 @@ static TECObjectRef CreateTECConverterForUTF8Variants(TextEncodingVariant varian
return [[self componentsSeparatedByString:@" "] lastObject];
}
 
- (BOOL)isNumeric {
if (self.length == 0) {
return NO;
}
NSCharacterSet *nonNumericCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
NSRange range = [self rangeOfCharacterFromSet:nonNumericCharacterSet];
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