Skip to content

Instantly share code, notes, and snippets.

@hac
Created January 16, 2010 18:04
Show Gist options
  • Save hac/278925 to your computer and use it in GitHub Desktop.
Save hac/278925 to your computer and use it in GitHub Desktop.
#include "KeywurlBrowserWindowController.h"
#include "KeywurlPlugin.h"
@implementation KeywurlBrowserWindowController
// We override this method to intercept addresses at an early stage without
// invoking Safari's fallback system. This is quicker as it avoids unnecessary
// DNS lookups
- (void) goToToolbarLocation: (id) sender {
KeywurlPlugin* plugin = [KeywurlPlugin sharedInstance];
KeywordMapper* mapper = [plugin keywordMapper];
NSString* input = [[_locationFieldEditor textStorage] string];
if (input) {
BOOL useDefault = NO;
NSArray *inputComponents = [input componentsSeparatedByString:@" "];
if ([mapper mappingForKeyword:[inputComponents objectAtIndex:0]])
// URL begins with a search keyword and a space.
{
useDefault = YES;
}
NSString* newUrl = [mapper mapKeywordInput: input withDefault: useDefault];
if (![input isEqualToString: newUrl]) {
[_locationFieldEditor->field setObjectValue: newUrl];
}
}
return [super goToToolbarLocation: sender];
}
- (id) keywurl_locationFieldEditor {
return _locationFieldEditor;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment