Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Undo Problems Again...Please Help

Undo Problems Again...Please Help
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 28, 2004, 05:33 PM
 
Hey guys,

What I am doing is inserting some text into a NSTextView using the code below:

- (void)applySnippetTagSnippet *)snippet
{
target = [[[NSDocumentController sharedDocumentController] currentDocument] textView];
if (target != nil && snippet != nil)
{
NSRange selectedRange = [target selectedRange];
NSMutableString *text = [[target textStorage] mutableString];
NSMutableString *selectedText = [NSMutableString stringWithString:[text substringWithRange:selectedRange]];
int cursorPosition = [snippet applySnippetToString:selectedText];
cursorPosition += selectedRange.location;
[target replaceCharactersInRange:selectedRange withString:selectedText];
[target setSelectedRange:NSMakeRange(cursorPosition, 0)];
}
}

Now, the text inserts fine, but it seems to cause some undo problems with the NSTextView it was inserted in.

For example, if I first type into my text view some random text, then insert the text, and then type some more after it. If I then place my cursor at the end of the document and try to undo, it'll work until I get to the text I inserted, I then begin to get these messages in the run log:

2004-05-28 23:30:21.753 Tag[2456] *** Assertion failure in -[NSMutableRLEArray objectAtIndex:effectiveRange:], String.subproj/NSAttributedString.m:1009
2004-05-28 23:30:21.756 Tag[2456] *** Assertion failure in -[NSMutableRLEArray objectAtIndex:effectiveRange:], String.subproj/NSAttributedString.m:1009
2004-05-28 23:30:21.857 Tag[2456] Access invalid attribute location 18 (length 18)
2004-05-28 23:30:22.198 Tag[2456] undo: NSUndoManager 0x4aa3b60 is in invalid state, undo was called with too many nested undo groups

If I then try and click in the text view, I get:

2004-05-28 23:30:24.287 Tag[2456] *** NSRunStorage, _NSBlockNumberForIndex(): index (18) beyond array bounds (18)

And can no longer type in the text view. I have tried adding an undo method with undo manager, but I still get the same errors.

Any ideas at all appreciated. This is the last bug remaining in my application and I'm really wanting to release this on Sunday, so any help at all is appreciated.

Thanks,
Oliver
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:33 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2