Need to click once on hyperlink before it activates?

Discussion in 'Mac Programming' started by fbs419, Oct 22, 2012.

  1. fbs419 macrumors newbie

    Sep 9, 2012
    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?

  2. fbs419 thread starter macrumors newbie

    Sep 9, 2012
    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.
  3. fbs419 thread starter macrumors newbie

    Sep 9, 2012
    Looks like this would do it:

    [[myText currentEditor] setSelectedRange:NSMakeRange(0, 0)];

Share This Page