From dbf63609283c8c43e88d461a08789051e7a5efe1 Mon Sep 17 00:00:00 2001 From: Francis Chong Date: Fri, 22 Feb 2013 15:09:33 +0800 Subject: [PATCH] When highlighted a token, typing using keyboard should ... - If enter is tapped, it should toggle the highlighted token, and ready the field for user input - If backspace is tapped, it should clear the current token - If any other key is tapped, it should replace current token with newly entered text --- JSTokenField/JSTokenButton.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; }