Skip to content
Browse files

Pasteboard reading uses NSTextCheckingResult when available for natur…

…al language recognition of URLs.
  • Loading branch information...
1 parent 1d009b9 commit 4ef561512fab9a169fcf63129037bfddfda6257b @mikeabdullah mikeabdullah committed
Showing with 36 additions and 1 deletion.
  1. +4 −0 KSWebLocationPasteboardUtilities.h
  2. +32 −1 KSWebLocationPasteboardUtilities.m
View
4 KSWebLocationPasteboardUtilities.h
@@ -44,6 +44,10 @@
- (id)initWithPasteboardPropertyList:(id)propertyList ofType:(NSString *)type;
+#pragma mark URL Guessing
++ (NSURL *)URLFromPasteboard:(NSPasteboard *)pboard; // like the WebView method, but takes advantage of NSTextCheckingTypeLink on 10.6+
+
+
#pragma mark 10.5 Pasteboard Support
+ (NSArray *)webLocationPasteboardTypes;
View
33 KSWebLocationPasteboardUtilities.m
@@ -121,7 +121,7 @@ + (KSWebLocation *)webLocationFromPasteboard:(NSPasteboard *)pasteboard;
{
KSWebLocation *result = nil;
- NSURL *URL = [WebView URLFromPasteboard:pasteboard];
+ NSURL *URL = [self URLFromPasteboard:pasteboard];
if (URL)
{
result = [KSWebLocation webLocationWithURL:URL
@@ -131,6 +131,37 @@ + (KSWebLocation *)webLocationFromPasteboard:(NSPasteboard *)pasteboard;
return result;
}
++ (NSURL *)URLFromPasteboard:(NSPasteboard *)pboard
+{
+ NSURL *result = [WebView URLFromPasteboard:pboard];
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+ if (!result)
+ {
+ NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
+ if ([spellChecker respondsToSelector:@selector(checkString:range:types:options:inSpellDocumentWithTag:orthography:wordCount:)])
+ {
+ NSString *string = [pboard stringForType:NSStringPboardType];
+
+ NSArray *checkResults = [spellChecker checkString:string
+ range:NSMakeRange(0, [string length])
+ types:NSTextCheckingTypeLink
+ options:nil
+ inSpellDocumentWithTag:0
+ orthography:NULL
+ wordCount:NULL];
+
+ if ([checkResults count])
+ {
+ result = [[checkResults objectAtIndex:0] URL];
+ }
+ }
+ }
+#endif
+
+ return result;
+}
+
#pragma mark Deprecated
+ (NSArray *)webLocationPasteboardTypes

0 comments on commit 4ef5615

Please sign in to comment.
Something went wrong with that request. Please try again.