Changing the text of an NSTextView without killing undos
Changing the text of an NSTextView without killing undos
- Subject: Changing the text of an NSTextView without killing undos
- From: Jonathan Wight <email@hidden>
- Date: Thu, 27 Nov 2003 23:35:36 -0600
Is there a way to modify the contents of an NSTextView without breaking
the undo stack?
For example, let's say a user has typed 'FOOBAR' into an empty
NSTextView. At this point I programmatically replace the 'FOOBAR' with
the text 'MOOF'. The user hits undo and suddenly the undo stack dies
complaining that it tried to removed 6 characters (the length of
'FOOBAR') when there were only 4 characters in the text view (the
length of 'MOOF'). Basically the undo stack is out of sync with the
actual contents of the text.
Now the obvious solution is to make my programatic modification
undoable. This does work. Unfortunately I need to modify the text in
response to the user's typing. The obvious place to do it is inside the
NSTextView's degelate method 'textDidChange'. Unfortunately even if my
changes are undoable the fact that I'm making my changes inside
textDidChange causes the undo stack to die just like it was before.
I've also tried making my changes inside NSTextStorage delegate's
textStorageWillProcessEditing method. But when I change the text there
I don't see the changes occur immediately in the text view.
Anyone got any suggestions?
Jon.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.