Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: understanding NSTextView undo?



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.

References: 
 >Re: understanding NSTextView undo? (From: Jim Correia <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.