understanding NSTextView undo?
understanding NSTextView undo?
- Subject: understanding NSTextView undo?
- From: Jim Correia <email@hidden>
- Date: Sat, 28 Dec 2002 15:30:45 -0500
I'm trying to understand the undo mechanism in NSTextView.
There doesn't seem to be much documentation about the mechanics. If
I've overlooked something important in the docs, can someone point me
at it?
Question 1:
It seems that undo of typing is coalesced. This presents a problem for
document applications because if you type, save, type, undo, it goes
back to past the save point. Is there a way to force the coalescing to
stop and start a new "group"? (This sounds like it should be a known
bug, but unless someone confirms that it is, I'll file a bug..)
Project Builder seems to do something with an alert (and perhaps some
other magic) to deal with this case.
TextEdit empties the undo stack on save, which while it works around
the problem, is sort of lame.
Question 2:
How do I make transformations in NSTextView undoable? The docs just say
"This method must be invoked at the start of any sequence of
user-initiated editing changes...." but don't say that it handles the
undo for you. Poking around in the debugger, it appears that it does
(and further, if it returns yes, and I do not subsequently replace the
text, it puts the text view in an inconsistent state.)
So, is making an action undoable as simple as
[textView shouldChangeTextInRange: range replacementString: string];
// do replacement
[textView didChangeText];
It seems to be that simple, but I want to make sure I'm not missing
something important here.
Also, without providing my own implementation of
shouldChangeTextInRange:replacementString: is it possible to affect the
range that will be selected on redo?
Imagine that a transform inserts
[macroStart] macroText [marcoEnd]
and leaves macroText selected so that the user can type a replacement
string.
But if I undo, then redo, the insertion point is left at the end of the
inserted text. It would be nice if the selection range were preserved.
Thanks,
Jim
(I've got other questions about the text suite scripting, undo, and
related things, but one step at a time..)
_______________________________________________
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.