diff --git a/AppKit/CPSearchField.j b/AppKit/CPSearchField.j index 1be2e07a4..0b4f89a23 100644 --- a/AppKit/CPSearchField.j +++ b/AppKit/CPSearchField.j @@ -109,8 +109,9 @@ var RECENT_SEARCH_PREFIX = @" "; [self setBezelStyle:CPTextFieldRoundedBezel]; [self setBordered:YES]; [self setEditable:YES]; - [self setDelegate:self]; [self setContinuous:YES]; + + [[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_searchFieldTextDidChange:) name:CPControlTextDidChangeNotification object:self]; var bounds = [self bounds], cancelButton = [[CPButton alloc] initWithFrame:[self cancelButtonRectForBounds:bounds]], @@ -198,7 +199,7 @@ var RECENT_SEARCH_PREFIX = @" "; /*! Resets the cancel button to its default attributes. - This method resets the target, action, regular image, and pressed image. By default, when users click the cancel button, the delete: action message is sent up the responder chain. This method gives you a way to customize the cancel button for specific situations and then reset the button defaults without having to undo changes individually. + This method resets the target, action, regular image, and pressed image. This method gives you a way to customize the cancel button for specific situations and then reset the button defaults without having to undo changes individually. */ - (void)resetCancelButton { @@ -420,7 +421,7 @@ var RECENT_SEARCH_PREFIX = @" "; [_cancelButton setHidden:([[self stringValue] length] === 0)]; } -- (void)controlTextDidChange:(CPNotification)aNotification +- (void)_searchFieldTextDidChange:(CPNotification)aNotification { if (![self sendsWholeSearchString]) { @@ -680,7 +681,8 @@ var RECENT_SEARCH_PREFIX = @" "; - (void)cancelOperation:(id)sender { [self setObjectValue:@""]; - [self _sendPartialString]; + [self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]]; + [self _updateCancelButtonVisibility]; } diff --git a/Tests/Manual/CPSearchField/AppController.j b/Tests/Manual/CPSearchField/AppController.j index ef4e13cc7..87d851ace 100644 --- a/Tests/Manual/CPSearchField/AppController.j +++ b/Tests/Manual/CPSearchField/AppController.j @@ -73,11 +73,18 @@ var categories = ["firstName","lastName"], [self changeCategory:[[searchField menu] itemAtIndex:1]]; [self updateFilter:searchField]; + + [searchField setDelegate:self]; [theWindow center]; [theWindow orderFront:self]; } +- (void)controlTextDidChange:(id)note +{ + CPLogConsole(_cmd); +} + - (void)awakeFromCib { [theWindow setBackgroundColor:[CPColor colorWithHexString:@"f3f4f5"]];