Closing a window with a textview using keyboard

  • I have a window that contains an NSTextView and an NSButton of type Push
    Button, whose Key Equiv. is set to "Return" ("\R") in Interface Builder in
    order to serve as the default button (closing the window) when hitting
    <return>.

    Of course, as soon as the textview gets the focus, pressing <return> results
    in a new line in the textview.

    How does one resolve this dilemma? My 1st idea was to use <enter> instead of
    <return>, but how do I set this in Interface Builder?

    Cheers,

    Knut
  • On 09.09.2007, at 22:18, Knut Lorenzen wrote:
    > How does one resolve this dilemma? My 1st idea was to use <enter>
    > instead of
    > <return>, but how do I set this in Interface Builder?

      I think you don't have to. Enter should be automatically re-mapped
    to the button that claims the return key. Or in short: It should Just
    Work(tm).

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • Uli Kusterer (<witness.of.teachtext...>) schrieb dereinst (am 09.09.2007
    23:22 Uhr):

    >> How does one resolve this dilemma? My 1st idea was to use <enter>
    >> instead of
    >> <return>, but how do I set this in Interface Builder?
    >
    > I think you don't have to. Enter should be automatically re-mapped
    > to the button that claims the return key. Or in short: It should Just
    > Work(tm).

    Thanks Uli, but that is exactly what I *don't* want. I would like to use
    <enter> *instead* of <return>.

    Cheers,

    Knut
  • On 10.09.2007, at 09:31, Knut Lorenzen wrote:
    > Uli Kusterer (<witness.of.teachtext...>) schrieb dereinst (am
    > 09.09.2007
    > 23:22 Uhr):
    >>> How does one resolve this dilemma? My 1st idea was to use <enter>
    >>> instead of
    >>> <return>, but how do I set this in Interface Builder?
    >>
    >> I think you don't have to. Enter should be automatically re-mapped
    >> to the button that claims the return key. Or in short: It should Just
    >> Work(tm).
    >
    > Thanks Uli, but that is exactly what I *don't* want. I would like
    > to use
    > <enter> *instead* of <return>.

      That would be non-standard. By default, the OS should do the
    following on a Mac:

    -> The default button always listens to return *and* enter.
    -> If a text field is there, it listens to return to mean "new
    line", but forwards "enter" to the default button.

    That means that users can rely on enter *always* triggering the
    default button, while return gives new lines in text fields, and is
    exchangeable with enter in all other cases.

    Don't try turning off the return key, it'll only confuse your users.

    That said, you could probably subclass NSTextView. It inherits some
    NSResponder methods that handle return and enter, and you could
    probably override one of those. But I would recommend overriding the
    "enter" key to pass it up the responder chain as un-handled, so that
    enter always works, and leave return untouched in your app. Because
    that's what all other apps do in this particular case, and reversing
    behaviour from users expectations only increases your tech support load.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
  • On 10.09.2007, at 11:50, Knut Lorenzen wrote:
    > Sorry, I must have been unclear. The behaviour I want is the
    > standard you
    > are describing above. But it simply does not work. BTW: I am
    > talking of a
    > text *view*, not a text *field*. Could that be the reason?

      No. NSTextView is actually easier than NSTextField, since every
    NSTextField shares one "field editor" (the NSTextView that does the
    actual work). So for an NSTextField, you'd have to subclass both
    classes, and make one return an instance of the other, while the pure
    NSTextView should be suitable for editing manually.

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
previous month september 2007 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