tinymce icon indicating copy to clipboard operation
tinymce copied to clipboard

I can't find what I'm looking for: api/tinymce/tinymce.undomanager.html

Open brichwin opened this issue 4 years ago • 5 comments

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.

brichwin avatar May 12 '21 16:05 brichwin

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

tylerkelly13 avatar May 13 '21 00:05 tylerkelly13

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?

ericbf avatar Oct 02 '23 21:10 ericbf

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.

TheSpyder avatar Oct 03 '23 06:10 TheSpyder

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.

tiny-stale-bot avatar Oct 03 '24 00:10 tiny-stale-bot

This would still be very useful.

ericbf avatar Oct 03 '24 00:10 ericbf

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.

tiny-stale-bot avatar Oct 04 '25 00:10 tiny-stale-bot

Still an issue.

ericbf avatar Oct 04 '25 13:10 ericbf

@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.

TheSpyder avatar Oct 15 '25 06:10 TheSpyder