Hi,

I've modified NSTextView: -mouseDown so that if our text storage contains 
attributed strings with the NSLinkAttributeName and we 'click' on such 
strings, NSTextView: -clickedOnLink: atIndex: is called so NSTextView's 
delegate textView: clickedOnLink: atIndex: method will be called too.

I included a patch with this mail.

Thanks,
        Ludovic

-- 
Live as if you were to die tomorrow.
Learn as if you were to live forever.
 - Gandhi
--- NSTextView.m.ori    Fri Dec 28 15:39:40 2001
+++ NSTextView.m        Fri Dec 28 15:22:30 2001
@@ -2121,7 +2121,7 @@
 {
   NSSelectionAffinity affinity = [self selectionAffinity];
   NSSelectionGranularity granularity = NSSelectByCharacter;
-  NSRange chosenRange, proposedRange;
+  NSRange chosenRange, proposedRange, urlRange;
   NSPoint point, startPoint;
   NSEvent *currentEvent;
   unsigned startIndex;
@@ -2138,6 +2138,19 @@
 
   startPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil];
   startIndex = [self characterIndexForPoint: startPoint];
+
+  // We search ouf textStorage for an attributed string with the 'link attribute'.
+  // If the attributed string is found, we build a NSURL object with the substring
+  // in the range of the attribute and we call clickedOnLink: atIndex:
+  if ( [_textStorage attribute: NSLinkAttributeName
+                    atIndex: startIndex
+                    effectiveRange: &urlRange] )
+    {
+      [self clickedOnLink: [NSURL URLWithString:[[_textStorage string] 
+substringWithRange: urlRange]]
+           atIndex: startIndex];
+
+      return;
+    }
 
   if ([_textStorage containsAttachments])
     {

Reply via email to