1

I'm having some issues trying to implement a way to have my undo and redo buttons automatically become enabled or disabled based on the UndoManager.

var editor = ace.edit(editorElement);

editor.on('change', function (e) {
  var um = editor.getSession().getUndoManager();
  $('button.undo').attr('disabled', um.hasUndo() ? false : true );
  $('button.redo').attr('disabled', um.hasRedo() ? false : true );
});

When you make the first change to the document it doesn't change the disabled state of the button. At this point the UndoManager hasn't been informed that there has been a change.

I didn't see any events that would be appropriate to test the state of the UndoManager in.

1 Answer 1

3

use input event instead of change event. undomanager is updated async after change event fires, and input event is emitted after that.

Sign up to request clarification or add additional context in comments.

1 Comment

Ha! I tried input earlier but I had something else wrong and I never went back to it. Thanks much, it worked great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.