From f2e89730421c69e66c3282b3597c528b3d0c4820 Mon Sep 17 00:00:00 2001 From: Greg Kempe Date: Fri, 6 Dec 2024 16:04:15 +0200 Subject: [PATCH] ignore in-flight saves when cancelling --- .../static/javascript/indigo/views/document_editor.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/indigo_app/static/javascript/indigo/views/document_editor.js b/indigo_app/static/javascript/indigo/views/document_editor.js index 63fe5f38b..88ea9c17d 100644 --- a/indigo_app/static/javascript/indigo/views/document_editor.js +++ b/indigo_app/static/javascript/indigo/views/document_editor.js @@ -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; @@ -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'); } @@ -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;