 |
 |
Weird Undo Bug
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hey guys,
I have been trying to figure out this undo bug I've been having recently, and thanks to FileMerge, I've found the bad code:
Code:
if ([[NSUserDefaults standardUserDefaults] stringForKey:@"TextTemplate"])
{
[docTextView insertText:[[NSUserDefaults standardUserDefaults] objectForKey:@"TextTemplate"]];
}
[All the above is done in awakeFromNib]
Basically, in preferences I have a text view that changes what is inserted on startup into my document NSTextView (docTextView). Now, if I leave the preferences text view empty, undo works on my main document window. But, if I put something into my preferences text view, undo does not work at all on my main document window. So I guess, that doing insertText on startup is somehow messing up the undo system for my main window.
Any ideas appreciated,
Oliver
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
I'm not sure why this isn't working, but here are a couple of things to look at: first, verify that your text view is editable and does actually use undo. Also, I get the impression that your text view is a part of a document, and that you're using NSDocument. If this is indeed the case, try calling [myFrickenDocument updateChangeCount: NSChangeDone] after you insert the text.
Finally, the code you posted, while fine, is sort of inefficient. It calls the user-defaults stuff twice and fetches your key from the user defaults dictionary twice. Here's a more optimized rendition:
Code:
NSString *textTemplate = [[NSUserDefaults standardUserDefaults] stringForKey:@"TextTemplate"];
if ( nil != textTemplate )
[docTextView insertText: textTemplate];
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Originally posted by smeger:
I'm not sure why this isn't working, but here are a couple of things to look at: first, verify that your text view is editable and does actually use undo. Also, I get the impression that your text view is a part of a document, and that you're using NSDocument. If this is indeed the case, try calling [myFrickenDocument updateChangeCount: NSChangeDone] after you insert the text. The reason for this is that your NSDocument manages the undo stack, and you aren't telling it that something that can be undone was performed.
Finally, the code you posted, while fine, is sort of inefficient. It calls the user-defaults stuff twice and fetches your key from the user defaults dictionary twice. Here's a more optimized rendition:
Code:
NSString *textTemplate = [[NSUserDefaults standardUserDefaults] stringForKey:@"TextTemplate"];
if ( nil != textTemplate )
[docTextView insertText: textTemplate];
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|