onChange fires after load, allows undo
WeeJeWel opened this issue · 7 comments
Because ng-model works with setValue, a change event is instantly fired after loading, and this also enables the user to undo (ctrl+z). Is this fixable?
I don't know. You want to disable the undo (to blank) when codemirror get initialized ?
So automatically cm.clearHistory(); affter the onLoad event ?
That did the trick. Thanks! 👍
You are welcome
I tried it like this:
<div class="codemirror-wrapper" data-shop-input-wrapper>
<div data-ui-codemirror="{ onLoad: codemirrorLoaded }" data-ui-refresh="true" data-ng-model="myVm.myHtml" data-ui-codemirror-opts="myVm.editorOptions()"></div>
</div>and
$scope.codemirrorLoaded = editor => {
editor.clearHistory();
};but it doesn't work. ctrl+z is still possible after init.
It is coming into the method.
Tried editor.doc.clearHistory() and editor.doc.cm.clearHistory() too but nothing helped. Ctrl + z after init is still removing everything from the editor without doing anything.
I added this and it worked:
$scope.codemirrorLoaded = editor => {
editor.on("change", function() {
editor.refresh();
editor.clearHistory();
editor.doc.clearHistory();
editor.doc.cm.clearHistory();
});
};Problem it will always avoid ctrl + z. I will check again some other stuffs. Do you have the real solution for this?