Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Pasteboard reading uses NSTextCheckingResult when available for natur…

…al language recognition of URLs.
  • Loading branch information...
commit 4ef561512fab9a169fcf63129037bfddfda6257b 1 parent 1d009b9
Mike Abdullah authored February 07, 2012
4  KSWebLocationPasteboardUtilities.h
@@ -44,6 +44,10 @@
44 44
 - (id)initWithPasteboardPropertyList:(id)propertyList ofType:(NSString *)type;
45 45
 
46 46
 
  47
+#pragma mark URL Guessing
  48
++ (NSURL *)URLFromPasteboard:(NSPasteboard *)pboard;   // like the WebView method, but takes advantage of NSTextCheckingTypeLink on 10.6+
  49
+
  50
+
47 51
 #pragma mark 10.5 Pasteboard Support
48 52
 + (NSArray *)webLocationPasteboardTypes;
49 53
 
33  KSWebLocationPasteboardUtilities.m
@@ -121,7 +121,7 @@ + (KSWebLocation *)webLocationFromPasteboard:(NSPasteboard *)pasteboard;
121 121
 {
122 122
     KSWebLocation *result = nil;
123 123
     
124  
-    NSURL *URL = [WebView URLFromPasteboard:pasteboard];
  124
+    NSURL *URL = [self URLFromPasteboard:pasteboard];
125 125
     if (URL)
126 126
     {
127 127
         result = [KSWebLocation webLocationWithURL:URL
@@ -131,6 +131,37 @@ + (KSWebLocation *)webLocationFromPasteboard:(NSPasteboard *)pasteboard;
131 131
     return result;
132 132
 }
133 133
 
  134
++ (NSURL *)URLFromPasteboard:(NSPasteboard *)pboard
  135
+{
  136
+    NSURL *result = [WebView URLFromPasteboard:pboard];
  137
+    
  138
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  139
+    if (!result)
  140
+    {
  141
+        NSSpellChecker *spellChecker = [NSSpellChecker sharedSpellChecker];
  142
+        if ([spellChecker respondsToSelector:@selector(checkString:range:types:options:inSpellDocumentWithTag:orthography:wordCount:)])
  143
+        {
  144
+            NSString *string = [pboard stringForType:NSStringPboardType];
  145
+            
  146
+            NSArray *checkResults = [spellChecker checkString:string
  147
+                                                        range:NSMakeRange(0, [string length])
  148
+                                                        types:NSTextCheckingTypeLink
  149
+                                                      options:nil
  150
+                                       inSpellDocumentWithTag:0
  151
+                                                  orthography:NULL
  152
+                                                    wordCount:NULL];
  153
+            
  154
+            if ([checkResults count])
  155
+            {
  156
+                result = [[checkResults objectAtIndex:0] URL];
  157
+            }
  158
+        }
  159
+    }
  160
+#endif
  161
+    
  162
+    return result;
  163
+}
  164
+
134 165
 #pragma mark Deprecated
135 166
 
136 167
 + (NSArray *)webLocationPasteboardTypes

0 notes on commit 4ef5615

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