Hi all,

I've got an app that presents a text field where the user can enter some text, press tab, and have the text auto-completed from a list of terms. I'm having a weird problem where the first tab triggers the expected events, the second tab gets inserted as a literal tab character without firing any events, but the third etc. tabs trigger events as expected.

The text field is an NSTextField and is set up to use the NSTextInput protocol to get control:textView:doCommandBySelector: events fired for, in this case, insertTab: events.

When the insertTab: selector is called, the code gets the text typed so far in the NSTextView, gets all the terms matching that prefix from a list, replaces the text with the longest unique prefix, and inserts the remainder of the first term from the list as marked text.

My problem is that once insertTab: has been called once—and the NSTextView has the first completion as marked text—the insertTab: selector doesn't get called when the user presses return; a literal tab character is inserted instead. If I then hit tab again (3rd time), insertTab: does get called.

I'm going slowly mad here, having sprinkled NSLog()'s every other line and checking the status of the First Responder on entry and exit of my handler[0].

[0] – Using the code example in 
<https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/EventOverview/EventHandlingBasics/EventHandlingBasics.html#//apple_ref/doc/uid/10000060i-CH5-SW23>

As far as I can tell I'm not doing anything in the handler that ought to affect this, and the First Responder is the same for both cases; and I can't see how the event chain could be different for the second (but not third) time the user presses tab. I'm at a loss as to how to continue debugging this.

Can someone suggest other approaches to debugging this?

This used to work under 10.4, but started exhibiting the above problems under 10.5+ (so possibly OS/Framework related, possibly compiler toolchain related). Can anyone think of any changes there that might be relevant? Something related to the planned deprecation of the NSTextInput protocol in favor of the NSTextInputClient protocol perhaps?


If anyone should be inclined, the relevant code is available at the URL below[1]. The relevant methods are tab_complete: and the "input_text" (NSTextField) delegates following it.

[1] – 
<http://github.com/xover/xchat-aqua/blob/master/fe-aqua/ChatWindow.mm#L2031>

--
  “If at first you don't succeed, keep shooting.”  -- monk

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to