• 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
shouldChangeTextInRanges and undo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

shouldChangeTextInRanges and undo


  • Subject: shouldChangeTextInRanges and undo
  • From: Ken Victor <email@hidden>
  • Date: Thu, 10 Nov 2005 17:39:15 -0800

i ran across a problem and have been able to recreate it a very simple test case. the problem is that if an override of
[NSTextView shouldChangeTextInRanges:replacementStrings:]
returns NO, NSTextView still registers an undo typing action! even tho the new text is not entered. (subsequent attempts at undo/redo don't work properly, but i believe thats just a consequence of the initial bug)


to see this, i created an almost codeless cocoa doc based app. in the doc window nib, i replaced the NSTextField with an undoable NSTextView and gave it a custom class. the custom class consists of only one method as follows:

- (BOOL) shouldChangeTextInRanges: (NSArray*) affectedRanges replacementStrings: (NSArray*) replacementStrings {
static NSMutableCharacterSet* cSet = nil;
BOOL result = [super shouldChangeTextInRanges: affectedRanges replacementStrings: replacementStrings];
if (result) {
if (!cSet) {
cSet = [NSMutableCharacterSet controlCharacterSet];
[cSet removeCharactersInString: @"\t"];
[cSet retain];
}
NSEnumerator* en = [replacementStrings objectEnumerator];
while (NSString* aRepStr = [en nextObject]) {
NSRange foundRange = [aRepStr rangeOfCharacterFromSet: cSet];
if (!(result = (foundRange.location == NSNotFound))) {
NSBeep();
break;
}
}
}


	return result;
	}

if you then run this app and type a return into the doc window, you'll hear the beep. but then notice that the window indicates the doc is dirty and the edit menu shows an undo typing item.

question 1) is there anything wrong with the above simple test implementation?

if not, then
question 2) is this a known bug? and if so, is there a known workaround? (and if so, what is it please? :-) )


if this is not known, i'll be happy to file a bug report.

thanx,
ken

ps. i didn't see anything in the archives about this and hence this post.
_______________________________________________
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


  • Follow-Ups:
    • Re: shouldChangeTextInRanges and undo
      • From: Douglas Davidson <email@hidden>
  • Prev by Date: Using observationInfo?
  • Next by Date: Re: Speeding up creation of NSDictionary from XML? (iTunes related)
  • Previous by thread: Using observationInfo?
  • Next by thread: Re: shouldChangeTextInRanges and undo
  • Index(es):
    • Date
    • Thread