angular-ui / ui-ace

This directive allows you to add ACE editor elements.
http://angular-ui.github.io/ui-ace
MIT License
578 stars 172 forks source link

Change to model resets the undo stack #125

Open antonpodolsky opened 9 years ago

antonpodolsky commented 9 years ago

Sometimes it is desired to preserve the undo stack when the model changes by using acee.setValue(ngModel.$viewValue, -1); instead of session.setValue(ngModel.$viewValue); which automatically resets the stack.

So the ngModel.$render function might look something like this:

var initialSetValue = true;
ngModel.$render = function () {
     if (initialSetValue) {
          session.setValue(ngModel.$viewValue);
          initialSetValue = false;
      else {
          acee.setValue(ngModel.$viewValue, -1);  // -1 moves the cursor to the first line and clears the selection made by setValue
      }
};

One caveat in the above solution is that hitting ctrl+z will undo the change but will also select all the text, so the fix might not be trivial.