RE: trouble with NSRange.location
RE: trouble with NSRange.location
- Subject: RE: trouble with NSRange.location
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Thu, 18 Dec 2003 12:39:12 -0500
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.