javascriptreactjsace-editorreact-ace

Ace editor. Set current edits state as base


I'm using ace editor wrapped by react-ace for my project.

How can I destroy all undo/redo history in certain moment when I need it?

I've tried this.aceRef.editor.destroy(); (just react ref bound with editor), but unfortunately it doesn't play well in some circumstances. So, I just need to clean undo/redo session/history or something like that.

Any solution?


Solution

  • Ace editor actually has this reset method with UndoManager.

    Then you need to assign temporary stored undomanager as base.

    It could be done smth like that:

    const { editor } = this.aceRef;
    const session = editor.getSession();
    const undoManager = session.getUndoManager();
    undoManager.reset();
    session.setUndoManager(undoManager);