Clear undo/redo stack upon receiving a concurrent delta (#12)

This commit is contained in:
Jonatan Kłosko 2021-01-22 20:43:56 +01:00 committed by GitHub
parent 3e6a4adce2
commit b8df31e1ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,8 +34,17 @@ export default class MonacoEditorAdapter {
applyDelta(delta) {
const operations = this.__deltaToEditorOperations(delta);
this.ignoreChange = true;
this.editor.getModel().pushEditOperations([], operations);
// Apply the operations without adding them to the undo stack
this.editor.getModel().applyEdits(operations);
this.ignoreChange = false;
// Clear the undo/redo stack as the operations may no longer be valid
// after applying the concurrent change.
// Note: there's not public method for getting EditStack for the text model,
// so we use the private attribute.
// (https://github.com/microsoft/vscode/blob/11ac71b27220a2354b6bb28966ed3ead183cc495/src/vs/editor/common/model/textModel.ts#L287)
const editStack = this.editor.getModel()._commandManager;
editStack.clear();
}
__deltaFromEditorChange(event) {