Re: understanding NSTextView undo?
Re: understanding NSTextView undo?
- Subject: Re: understanding NSTextView undo?
- From: Jim Correia <email@hidden>
- Date: Sun, 29 Dec 2002 12:18:35 -0500
On Saturday, December 28, 2002, at 09:22 PM, Jim Correia wrote:
Yes, that would be nice.
I guess I would approach this by using your own controller object
with -insertMacro: and -deleteMacro: methods, and have them register
each other to undo each other's actions. You can set the selection
range appropriately in each instead of depending upon NSTextView's
undo management.
I could go down this road. The only down side is that I'd have to do
all that shouldChangeTextInRange: replacementString: does except for
creating the undo object (so if the delegate wanted to reject the
change, it could, etc.)
It actually turns out that there is a simpler solution.
After changing the text, I do
[[[self undoManager] prepareWithInvocationTarget: self]
undoRedoSelectionRange: selectedRange];
The "correct" range is selected on undo, so the method just has to do
this:
- (void)undoRedoSelectionRange:(NSRange)range
{
[[[self undoManager] prepareWithInvocationTarget: self]
undoRedoSelectionRange: range];
if ([[self undoManager] isRedoing])
{
[[self firstTextView] setSelectedRange: range];
}
}
Jim
_______________________________________________
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.