I can't find what I'm looking for: api/tinymce/tinymce.undomanager.html
I've tried to understand how to use the undo manager when authoring a TinyMCE plugin. I don't understand the overall philosophy:
- What is an Undo Level (add) vs.
- What is an Undo Bookmark (beforeChange)
- What is the best practice for using the api if I am supplying the user a button that styles content, mutates the document?
- Do I need to always use transact to call my mutator function? Or is it a option? What's the best practice?
For example, my plugin provides an interface for selecting text and wrapping it with a so they can markup the human language changes in the text. It does that by applying a format. I've tried every combo I can imagine to make it work with undo to no avail.
Hi @brichwin,
The TinyMCE developers have better understanding of this. I'll transfer this ticket to tinymce/tinymce so they can answer these questions and transfer the ticket back so I can document the explanation. I'll keep an eye on this ticket in case it gets closed by accident rather than transferred.
Tyler
Nothing ever came of this? I’m also trying to work with the UndoManager, but can’t seem to get the desired functionality out of it. In my case, I just need to clear the redo stack (as if the user made a change, but without adding anything to the undo stack). Is this possible?
Sadly no, the index (which indicates where in the data array the split from undo to redo begins) is a private variable.
https://github.com/tinymce/tinymce/blob/02a9b5480ffd56b4ffda14e5b8d0afb75c76ad3d/modules/tinymce/src/core/main/ts/api/UndoManager.ts#L19
You could possibly monitor for undo events and try to mirror the index, so you can shave off unwanted redo events, but I don't know how well that would work so I can't really recommend it.
This issue is stale because it has been open 365 days with no activity. Please comment if you wish to keep this issue open or it will be closed in 30 days.
This would still be very useful.
This issue is stale because it has been open 365 days with no activity. Please comment if you wish to keep this issue open or it will be closed in 30 days.
Still an issue.
@ericbf perhaps try using undoManager.add()? I know you don't want to add a level but that's the only way the data resets at the moment.
https://github.com/tinymce/tinymce/blob/291454d0ac1bf89e8a07ce82dc01fd50fad94bac/modules/tinymce/src/core/main/ts/undo/Operations.ts#L69-L72
Note that undo add will do nothing if the content hasn't changed.