Re: trouble with NSRange.location
Re: trouble with NSRange.location
- Subject: Re: trouble with NSRange.location
- From: Robert Burns <email@hidden>
- Date: Thu, 18 Dec 2003 16:06:41 -0600
Thanks to you both. You both pointed me right to my errors; and quite a
quick response too. I'm slowly but surely 'getting it' (tm).
On Dec 18, 2003, at 11:45 AM, Fritz Anderson wrote:
Looking at the documentation for -[NSTextStorage editedRange], I
notice that it is intended for use by delegates and layout methods of
NSTextStorage, during processes and notifications that occur and have
been cleaned up before the NSTextView textDidChange: notification you
call it in. The documentation says "Returns the range of the receiver
to which _pending_ changes have been made, whether of characters or of
attributes." It's therefore not surprising that the range is no longer
valid when the changes are no longer pending.
The constant 2147483647 (hex 0x7fffffff), when used in an NSRange
location, is named as NSNotFound; it indicates the NSRange is not
valid data. You shouldn't be relying on your observations of the
length field. Sorry for the bad news.
-- F
On Dec 18, 2003, at 11:39 AM, Jonathan E. Jackel wrote:
I think the problem may be that by the time you are notified of the
editing,
it is done. You are "listening" for textDIDChange (emphasis added),
which
suggests to me that the change has already been made when the
notification
is sent. There would therefore be no "editedRange" anymore. That is
consistent with the values your are receiving, which look suspiciously
like
{NSNotFound, 0}, which is the range you generally get if you look for
something that doesn't exist.
Is there some reason you aren't
using -textView:shouldChangeTextInRange:replacementString:? Notice
that
this is a "should" method, not a "did" method. Should methods are
invoked
before the change is actually made, and essentially ask permission to
make
the change. Also, you get the range you are interested in passed to
you in
the second argument, so you don't have to ask the text storage for it,
although you probably could.
Jonathan
Robert Burns wrote:
I've searched the archives and much documentation and can't understand
what's going wrong with my use of an NSTextStorage editedRange.
Whenever I get the editedRange.location (and I've tried this many
different ways) I always get the integer 2147483647 instead of
something within the length of the text. If I get the
editedRange.length it gives me exactly what I expect (i.e., 1 if no
text is selected, 0 if it's a backspace delete, and n when selected
text is changedf n characters in length). So does anyone know what I'm
missing here?
This class is serving as a delegate to an NSTextView, established in
IB.
Thanks,
Rob Burns
ps, code follows:
#import "LLTempoController.h"
@implementation LLTempoController
- (void)textDidChange:(NSNotification *)notification;
{
NSLog(@"retainCount of notification is %d", [notification
retainCount]);
theText = [[notification object] textStorage];
unsigned int insertionIndex = [theText editedRange].location; //
it's always 2147483647;
unsigned int insertionLength = rangeForInsertion.length;
NSLog(@"insertionIndex in first routine is %d", insertionIndex);
NSLog(@"insertionLength in first routine is %d",
insertionLength);
}
@end
_______________________________________________
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.