• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: over-riding the behaviour of the tab key in a NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: over-riding the behaviour of the tab key in a NSTextView


  • Subject: Re: over-riding the behaviour of the tab key in a NSTextView
  • From: Douglas Davidson <email@hidden>
  • Date: Tue, 19 Mar 2002 14:21:37 -0800

On Tuesday, March 19, 2002, at 12:15 PM, Jake MacMullin wrote:

Is there a way of temporarily changing the behaviour of a certain key in a NSTextView without sub-classing it? For example, I have written a program that auto-completes words. After you type three characters it guesses the word you want and inserts the remaining characters after the insertion point and highlights them (so you can keep typing if you don't want to keep the suggestion). However, most implementations of auto-completion seem to use the tab key as a way of accepting the suggestion. In my case, as the suggestion is highlighted, pressing the tab key just replaces it with a tab.

Here is the normal sequence when a text view receives key events: NSTextView's keyDown: passes events to interpretKeyEvents:, which is where they enter key binding and input management. They come out either as insertText: or as doCommandBySelector: (see NSResponder.h for these three methods).

In particular, an tab will (with the standard key bindings) end up using doCommandBySelector: to call insertTab: on the NSTextView. If the textview is not a field editor, this will call insertText: to insert a tab character. If it is a field editor (for example, when editing a textfield) this will end editing instead. An arbitrary text view can be made to act in either of these ways by calling setFieldEditor:.

To do something special here, you should be able to implement the text view delegate method

- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector;

and, if aSelector == @selector(insertTab:), do something special.

Alternatively, if you wished to do this in a text view subclass rather than in the delegate, you could override insertTab: to similar effect.

Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >over-riding the behaviour of the tab key in a NSTextView (From: Jake MacMullin <email@hidden>)

  • Prev by Date: Re: Several questions on Objective C
  • Next by Date: Arrow keys
  • Previous by thread: over-riding the behaviour of the tab key in a NSTextView
  • Next by thread: Re: over-riding the behaviour of the tab key in a NSTextView
  • Index(es):
    • Date
    • Thread