• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: understanding NSTextView undo?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

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

  • Prev by Date: Re: Getting Mouse Moved Events
  • Next by Date: Re: Using NSCell to bold cells in a tableview
  • Previous by thread: Re: understanding NSTextView undo?
  • Next by thread: Re: understanding NSTextView undo?
  • Index(es):
    • Date
    • Thread