Skip to content

Instantly share code, notes, and snippets.

@dhruvpsaru
Last active November 18, 2016 12:16
Show Gist options
  • Save dhruvpsaru/abe9f98335a92d623e043bb8ff693fa0 to your computer and use it in GitHub Desktop.
Save dhruvpsaru/abe9f98335a92d623e043bb8ff693fa0 to your computer and use it in GitHub Desktop.
How to enable undo and redo in ace editor

How to deal with undomanager in ace editor

  • Have under imports
var UndoManager = require("ace/undomanager").UndoManager;
var undoManager = new UndoManager();
  • Then add
 editor.getSession().setUndoManager(this.undoManager);
  • Then for binding part use under method
this._bindKeys = function(){
             this.editor.commands.addCommands([
                 {
                     name : 'undo',
                     bindKey : 'Ctrl-Z',
                     exec : function(editor){
                         editor.session.getUndoManager().undo();
                     }
                 },
                 {
                     name : 'redo',
                     bindKey : 'Ctrl-Y',
                     exec : function(editor){
                         editor.session.getUndoManager().redo();
                     }
                 }
             ]);
         };
  • Call this method once during initiation to bind undo and redo
  • You can also bind keys as bindKey: {win: "Ctrl-Z", mac: "Command-Z"}, for supporting mac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment