forked from atombender/keywurl
/
KeywurlBrowserWindowController.m
33 lines (29 loc) · 1.19 KB
/
KeywurlBrowserWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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;
if ([input rangeOfString: @" "].location != NSNotFound ||
[input rangeOfString: @"."].location == NSNotFound) {
// URL contains spaces and is not a single word that contains dots,
// so it's pretty much guaranteed to not be a URL
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