Skip navigation.
 
mlRe: NSTextfields and keyboard equivalents - am I missing something?
FROM : John Stiles
DATE : Mon Apr 21 19:05:11 2008

In "The Path Of Key Events" in the URL you posted, the #1 item in the
list is "key equivalents."
AppKit checks keyDown events to see if command is held; if it is, it
tries to match it against the menus before passing it through the
responder chain.
I think your best bet is to dim your menu item or remove its key
equivalent when a text field gains first responder, and then restore it
when the text field loses first responder.

Mattias Arrelid wrote:
> I have a simple test application with a few custom menu items. Let's
> assume that _none_ of these items has a key equivalent of COMMAND +
> (right arrow) for now.
>
> When the first responder of the application is an NSTextField, and the
> user produces COMMAND + (right arrow), the insertion point is being
> placed right after the last character in the text field. This is true
> as long as the text field stays the first responder. As mentioned
> earler, I _don't_ have a menu item with such a key equivalent at this
> point.
>
> If I add a menu item that _has_ a key equivalent of COMMAND + (righ
> arrow), what happens is that this item's action is performed when I
> press the above key combo - even if the text field is the first
> responder. Is this supposed to happen? When reading the Cocoa
> Event-Handling documentation, I stumbled upon this:
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/chapter_2_section_3.html#//apple_ref/doc/uid/10000060i-CH3-SW10
>
> Inspired by that, I enabled some breakpoints in my project. From
> these, I can see that the text field doesn't seem to care about saying
> "yes, I do respond to COMMAND + (right arrow)" when its
> "performKeyEquivalent:" is called, which explains why the menu item
> gets the action eventually. Is this correct?
>
> To sum things up: I want the text field to respond to all "standard"
> key equivalents (move cursor to front, end, move word forward/backward
> etc.), even if I have a menu item with such a key equivalent. There
> are applications that behave like this, e.g. iTunes, and I do think
> that this is the correct behavior. Could anyone point me in the right
> direction here?
>
> Regards
> Mattias
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
>

Related mailsAuthorDate
mlNSTextfields and keyboard equivalents - am I missing something? Mattias Arrelid Apr 21, 18:27
mlRe: NSTextfields and keyboard equivalents - am I missing something? John Stiles Apr 21, 19:05
mlRe: NSTextfields and keyboard equivalents - am I missing something? Mattias Arrelid Apr 22, 23:28
mlRe: NSTextfields and keyboard equivalents - am I missing something? John Stiles Apr 22, 23:54