Re: Typing into a NSTextView and overriding it
Re: Typing into a NSTextView and overriding it
- Subject: Re: Typing into a NSTextView and overriding it
- From: Quincey Morris <email@hidden>
- Date: Mon, 20 Feb 2017 23:24:20 -0800
- Feedback-id: 167118m:167118agYYG0F:167118sA0Gr-tTY-:SMTPCORP
On Feb 20, 2017, at 23:07 , Daryle Walker <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden