Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pasteboard reading uses NSTextCheckingResult when available for natur…

…al language recognition of URLs.
  • Loading branch information...
commit 4ef561512fab9a169fcf63129037bfddfda6257b 1 parent 1d009b9
@mikeabdullah mikeabdullah authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.