Skip to content

Commit

Permalink
Merge pull request #8 from ShannonChenCHN/master
Browse files Browse the repository at this point in the history
[FIX] Emojis get torn apart at the last limited index(Objective-C only)
  • Loading branch information
tingxins authored Dec 3, 2017
2 parents 9157cd8 + a47a686 commit 3c534de
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion InputKit/TXLimitedTextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ - (void)textFieldTextDidChangeNotification:(NSNotification *)notification {
if (!position) {
BOOL flag = NO;
if (currentText.length > maxLength) {
textField.text = [currentText substringToIndex:maxLength];
// Use the rangeOfComposedCharacterSequenceAtIndex: method
// to make sure that Unicode characters, like emojis, don’t get torn apart.
NSRange range = [currentText rangeOfComposedCharacterSequenceAtIndex:maxLength];
textField.text = [currentText substringToIndex:range.location];
flag = YES;
}

Expand Down

0 comments on commit 3c534de

Please sign in to comment.