Skip to content

Commit

Permalink
ignore in-flight saves when cancelling
Browse files Browse the repository at this point in the history
  • Loading branch information
longhotsummer committed Dec 6, 2024
1 parent 9b9db43 commit f2e8973
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions indigo_app/static/javascript/indigo/views/document_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
this.editing = false;
// flag to prevent circular updates
this.updating = false;
// nonce to prevent concurrent saves
this.nonce = null;
this.document = this.parent.model;
// the element currently being shown
this.xmlElement = null;
Expand Down Expand Up @@ -126,8 +128,11 @@

let elements;
try {
// TODO: handle cancel mid-way through
// use a nonce to check if we're still the current save when the parse completes
const nonce = this.nonce = Math.random();
elements = await this.aknTextEditor.parse() ;
// check if we're still the current save
if (nonce !== this.nonce) return;
} finally {
btn.removeAttribute('disabled');
}
Expand All @@ -147,7 +152,7 @@
},

closeTextEditor: function(e) {
// TODO: cancel any pending update
this.nonce = null;
this.toggleTextEditor(false);
this.toolbar.classList.remove('is-editing', 'edit-mode-text');
this.editing = false;
Expand Down

0 comments on commit f2e8973

Please sign in to comment.