diff --git a/JSTokenField/JSTokenButton.m b/JSTokenField/JSTokenButton.m index f20112b..1e5255f 100644 --- a/JSTokenField/JSTokenButton.m +++ b/JSTokenField/JSTokenButton.m @@ -112,11 +112,21 @@ - (void)deleteBackward { - (BOOL)hasText { return NO; } + - (void)insertText:(NSString *)text { + NSString *trimmedText = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if ([text hasPrefix:@"\n"]) { + [_parentField.textField becomeFirstResponder]; + } else if ([trimmedText length] > 0) { + [_parentField.textField setText:trimmedText]; + [_parentField.textField becomeFirstResponder]; + [self deleteBackward]; + } else { + [self resignFirstResponder]; + } return; } - - (BOOL)canBecomeFirstResponder { return YES; }