While working with the ACE Editor, I noticed a terrifying feature. They call it "undo".
OK so maybe it's not that terrifying, but it does have a terrifying behavior—it undos back beyond when a new project is started. That is, it undos back to when the editor was empty. So, hitting multiple Ctrl-Z's will eventually land you, not on the original version of the project, but on a blank page. Since I am auto-saving my work in localStorage, I very quickly have a blank project with no obvious means to restore my work.
I do not see any obvious way to remove an entry from ACE's UndoManager. I do see that EditSession has a
setUnderManager()method—perhaps I can use that to initialize the undo at the point just after the editor is updated with
So I do just that:
setValue()changes the contents (or generalize a code editor
setValuefunction). But first, I need to make sure this works.
Uncaught ReferenceError: UndoManager is not definedAh, it seems that I will have to require.js it into my current namespace. I try:
var UndoManager = require("ace/ace").UndoManager;But that does not work. It seems that
UndoManageris not a property of the ACE constructor.
define()statement for UndoManager is:
define('ace/undomanager', /* ... */);This suggests that the following might work:
var UndoManager = require("ace/undomanager"); editor.getSession().setUndoManager(new UndoManager());However, I still seem to lack a constructor:
UndoMangerproperty of that require object:
And indeed, the following does the trick:
// ... ace.setValue(/* ... */); var UndoManager = require("ace/undomanager").UndoManager; ace.getSession().setUndoManager(new UndoManager());Not only so the page load without error, but undo works as desired. I can type a bunch of junk in my current project, Ctrl-Z to my heart's content, but never move back to the blank page before the first