On Feb 20, 2017, at 23:07 , Daryle Walker <dary...@mac.com> wrote:
> 
> 1. How can one type in control characters into a text-view? I mean ASCII 
> range 0 through 31 and 127, not counting horizontal-tab and line-feed.

You probably can’t, although it’s not entirely clear. Holding down the Control 
key and pressing another key will send a key event for a control character 
through the text system, and if un-intercepted it may well end up being 
translated into an ASCII controller character, but many will be intercepted as 
control or editing functions. For example, this email text is likely a 
NSTextView, and various Control+key combinations that I tried were interpreted 
as cursor navigation, etc.

However, a text view delegate can receive a notification (via NSTextDelegate 
protocol) when text changes, so your code can be aware of what characters find 
their way into text, as they’re typed.

(Also, in a Unicode world, what characters do you really mean to exclude. 
Unicode encompasses ASCII control characters, but there are others that you 
might want to disallow. Any of these can be entered into text via the 
Characters panel that can be enabled in System Preferences.)

> 2. Is there a way to filter out the user from typing (or pasting, etc.) 
> characters you don't want (like NUL)?

textDidChange notification, as above. If not other delegate methods.

> 3. Is there a way to limit the length of a line? Probably using a testing 
> function.

textDidChange notification.

However, filtering out characters during typing is often a subtler problem that 
appears at first, and can lead to a frustrating user experience. It may well be 
a better idea, overall, to place no limits on what can be typed, but to 
validate the final text when it actually needs to be used.

_______________________________________________

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to