-
-
Save augard/4086223 to your computer and use it in GitHub Desktop.
Forwarding keydown event to a search field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)goToProductListWithEvent:(NSEvent *)event | |
{ | |
self.selectedViewController = _productListViewController; | |
[self.view.window makeFirstResponder:_productListViewController.searchField]; | |
_productListViewController.searchField.stringValue = [event characters]; | |
int64_t delayInSeconds = 0.01; | |
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); | |
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ | |
NSWindow *window = self.view.window; | |
NSText *fieldEditor = [window fieldEditor:YES forObject:_productListViewController.searchField]; | |
[fieldEditor setSelectedRange:NSMakeRange(1, 0)]; | |
[_productListViewController updateFilter:_productListViewController.searchField]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment