Re: customizing TextView keyboard responses
Re: customizing TextView keyboard responses
- Subject: Re: customizing TextView keyboard responses
- From: Douglas Davidson <email@hidden>
- Date: Tue, 18 Dec 2001 16:22:56 -0800
On Tuesday, December 18, 2001, at 09:04 AM, Matt Neuburg wrote:
No, it's more complicated than that, because I want Return characters
to be
entered as usual. I don't want a TextField; I want a TextView with just
this one customized bit of behavior. m.
This question last came up in the context of distinguishing between
enter and return; let me crib from what I said then.
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 enter or return will (with the standard key bindings)
end up using doCommandBySelector: to call insertNewline: on the
NSTextView. If the textview is not a field editor, this will call
insertText: to insert a newline 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:.
A tab or backtab will (with the standard key bindings) end up using
doCommandBySelector: to call insertTab: or insertBacktab: on the
NSTextView. If the textview is not a field editor, insertTab: will call
insertText: to insert a tab character; insertBacktab: will do nothing.
If it is a field editor, this will end editing instead.
You should be able to implement the text view delegate method
- (BOOL)textView:(NSTextView *)aTextView
doCommandBySelector:(SEL)aSelector;
and check whether aSelector == @selector(insertTab:), if you choose not
to make your text view a field editor, or whether aSelector ==
@selector(insertNewline:), if you choose to make your text view a field
editor, and at that point do something other than the default.
Alternatively, if you wished to do this in a text view subclass rather
than in the delegate, you could override insertTab: or insertNewline: to
similar effect.
Douglas Davidson
hopoteroi de hemon erchontai epi ameinon pragma, adelon panti plen e toi
theoi