Mac Need to click once on hyperlink before it activates?

fbs419

macrumors newbie
Original poster
Sep 9, 2012
8
0
I have a panel with a hyperlink on it. I used some code from Technical Q&A1487 (Embedding Hyperlinks in NSTextField and NSTextView), and to get the hand cursor, I tried both a small subclass of NSTextView, implementing resetCursorRects, and the DSClickableURLText class. In both cases, when my panel comes up, I have to click once on the hyperlink before I see the hand cursor and can go to the URL. I call selectText: self (in fact, I have to, or I can't ever get to the URL). I've also tried calling makeFirstResponder on the window. But I still have to click on it once before it works.

Is this just an anomaly in the OS or the kit? Is there a way I can get this to work programmatically, but simulating a click?

Thanks
 

fbs419

macrumors newbie
Original poster
Sep 9, 2012
8
0
I did see this post:

===
You need to use an NSTextView here rather than an NSTextField. The
behavior you are seeing is because an NSTextField is not 'active'
until clicked upon, and then it gets the window's field editor (which
is a shared NSTextView used by all fields on the window), and places
that view on top of the text field and uses it to edit the text. It is
NSTextView that handles the link hand cursor, and et cetera.
===

Isn't there any way around this? Without the NSTextField subclass code, even though the font changes, at least it goes to the hyperlink on the first click. I tried using an NSTextView, and it wasn't working.
 

fbs419

macrumors newbie
Original poster
Sep 9, 2012
8
0
Looks like this would do it:

[[myText currentEditor] setSelectedRange:NSMakeRange(0, 0)];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.