• 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: Advice on restricting/monitoring character input in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Advice on restricting/monitoring character input in NSTextView


  • Subject: Re: Advice on restricting/monitoring character input in NSTextView
  • From: Scott Lehman <email@hidden>
  • Date: Mon, 6 Feb 2006 23:24:54 -0800 (PST)

Well I have to confess that I'm not sure what to do
with that.  I thought the docs state that the field
editor is for controls, which made sense to me -
having an NSTextView instance as a field editor for an
NSTextView seems redundant and unecessary.  Or is it?

I realize now that while the NSTextStorage delegate
may provide a nice hook, it poses problems for undo.
If I filter out a key stroke, it should be before the
action is registered for undo.

So now I'm thinking subclassing NSTextView might be
the way to go.  Is it as simple as:

-Override insertText: to include filtering/processing
(this covers both key press and pastes, correct?)
-Either call [super insertText:aString] with any input
I want, or return immediately if I want to ignore it

?

Thanks,

Scott

--- Keith Wilson <email@hidden> wrote:

> I think you need to look at NSWindow's
>
> fieldEditor: forObject:
>
> Keith
>
> On 07/02/2006, at 11:28 AM, Scott Lehman wrote:
>
> > I'm looking to prevent some characters and
> sequences
> > (such as tabs and consecuive spaces for starters)
> from
> > being entered into my NSTextView.  After some
> > searching of the list archives, I know to steer
> clear
> > of overriding keyDown: and have the following
> > strategy:
> >
> > For input from the keyboard:
> > -Use the delegate
> > shouldChangeTextInRange(s):replacementString(s)
> > methods (Can I safely assume this is called one
> > character at a time for keyboard input?)
> > -Use delegate textView:doCommandBySelector:
> methods
> > for intercepting special keys (i.e. the insertTab:
> > command, though the previous method can easily
> handle
> > tabs)
> >
> > For input from the pasteboard:
> > -Create a NSTextView subclass to override the
> paste
> > text methods, including some text filtering before
> > inserting any text
> >
> > I think that will work, I would much prefer to
> have
> > the filtering/processing centralized in one place.
> > Are there other strategies to consider that let me
> > catch all text input, be it key presses, the
> > pasteboard, or any other source I'm unaware of?
> >
> >
> > I found the NSTextStorage delegate method
> > textStorageWillProcessEditing: which appears to be
> a
> > good hook to clean up text input.  Any issues with
> > using that?
> >
> > Is there anything else earlier in the text input
> chain
> > of command?  Is there a safe way to change input
> in a
> > custom text storage class'
> > replaceCharactersInRange:withString:
> implementation?
> >
> > Thanks,
> >
> > Scott
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >  _______________________________________________
> > Do not post admin requests to the list. They will
> be ignored.
> > Cocoa-dev mailing list
> (email@hidden)
> > Help/Unsubscribe/Update your Subscription:
> >
>
>
> > 40bigpond.net.au
> >
> > This email sent to email@hidden
>
>



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Advice on restricting/monitoring character input in NSTextView (From: Keith Wilson <email@hidden>)

  • Prev by Date: Re: NSTableColumn Bindings and italics
  • Next by Date: Re: How to change the strings in application menu
  • Previous by thread: Re: Advice on restricting/monitoring character input in NSTextView
  • Next by thread: Re: Advice on restricting/monitoring character input in NSTextView
  • Index(es):
    • Date
    • Thread