NSTextField Selection

  • I have an NSTextField whose width is just enough for M and W.  The filled can get set with text longer than one character. The user is to replace this multi-character text with a single character.

    So, without having to double click to select all text before entering the single character replacement what is the best way to programmatically select the text?

    Do I subclass NSTextField , define a tracking rect and look for mouse entered and then -selectText?  Seems extreme. Is there an easy way?

    -koko
  • On Jun 15, 2012, at 12:31 PM, koko <koko...> wrote:

    > I have an NSTextField whose width is just enough for M and W.  The filled can get set with text longer than one character. The user is to replace this multi-character text with a single character.

    I'm really confused by your description of this interface. How and why can the field be filled with more than one character?

    >
    > So, without having to double click to select all text before entering the single character replacement what is the best way to programmatically select the text?

    Actually selecting the text is the easy part. Just call -selectText:.

    >
    > Do I subclass NSTextField , define a tracking rect and look for mouse entered and then -selectText?  Seems extreme. Is there an easy way?

    What do you want the trigger to be for selecting all the text? "Whenever the user starts editing my text field, all the text should be selected so they can hit one key to replace it all?"

    If that's what you want, I'd just hook up an object as the text field's delegate and implement -controlTextDidBeginEditing: to select all text in the field editor (accessible via the @"NSFieldEditor" key of the notification's user info dictionary).

    --Kyle Sluder
  • You are going around the world to cross the street. Define an NSFormatter for your text field and implement a textfield delegate and you can have the exact control over the textfield that you are after.

    On Jun 15, 2012, at 3:41 PM, Kyle Sluder wrote:

    > On Jun 15, 2012, at 12:31 PM, koko <koko...> wrote:
    >
    >> I have an NSTextField whose width is just enough for M and W.  The filled can get set with text longer than one character. The user is to replace this multi-character text with a single character.
    >
    > I'm really confused by your description of this interface. How and why can the field be filled with more than one character?
    >
    >>
    >> So, without having to double click to select all text before entering the single character replacement what is the best way to programmatically select the text?
    >
    > Actually selecting the text is the easy part. Just call -selectText:.
    >
    >>
    >> Do I subclass NSTextField , define a tracking rect and look for mouse entered and then -selectText?  Seems extreme. Is there an easy way?
    >
    > What do you want the trigger to be for selecting all the text? "Whenever the user starts editing my text field, all the text should be selected so they can hit one key to replace it all?"
    >
    > If that's what you want, I'd just hook up an object as the text field's delegate and implement -controlTextDidBeginEditing: to select all text in the field editor (accessible via the @"NSFieldEditor" key of the notification's user info dictionary).
    >
    > --Kyle Sluder

    Charlie Dickman
    <3tothe4th...>
  • On Jun 15, 2012, at 1:53 PM, Charlie Dickman wrote:

    > You are going around the world to cross the street. Define an NSFormatter for your text field and implement a textfield delegate and you can have the exact control over the textfield that you are after.

    NSFormatter doesn't sound appropriate here, but that's because OP hasn't been very clear about his motivations.

    If your goal is to control the selection behavior of the editing process, then NSFormatter is not the right choice. But perhaps controlling the selection is only a perceived required step on the way to OP's actual goal.

    --Kyle Sluder
  • On Jun 15, 2012, at 1:41 PM, Kyle Sluder wrote:

    > What do you want the trigger to be for selecting all the text? "Whenever the user starts editing my text field, all the text should be selected so they can hit one key to replace it all?"
    >
    > If that's what you want, I'd just hook up an object as the text field's delegate and implement -controlTextDidBeginEditing: to select all text in the field editor (accessible via the @"NSFieldEditor" key of the notification's user info dictionary).

    Just what I was looking for!

    -koko
  • On Jun 15, 2012, at 1:41 PM, Kyle Sluder wrote:

    > What do you want the trigger to be for selecting all the text? "Whenever the user starts editing my text field, all the text should be selected so they can hit one key to replace it all?"
    >
    > If that's what you want, I'd just hook up an object as the text field's delegate and implement -controlTextDidBeginEditing: to select all text in the field editor (accessible via the @"NSFieldEditor" key of the notification's user info dictionary).

    This is what I was looking for.  Thanks.

    -koko
previous month june 2012 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today