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.
Sometimes it is desired to preserve the undo stack when the model changes by using
acee.setValue(ngModel.$viewValue, -1);
instead ofsession.setValue(ngModel.$viewValue);
which automatically resets the stack.So the ngModel.$render function might look something like this:
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.