From 77dcc1c70593296815bb160a60751291d4d4408e Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 9 Jan 2018 12:44:25 +0100 Subject: [PATCH] Fix a race condition when switching language in the code app --- www/code/inner.js | 2 +- www/common/sframe-common-codemirror.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/www/code/inner.js b/www/code/inner.js index 7417206c4..e7bdfb5f1 100644 --- a/www/code/inner.js +++ b/www/code/inner.js @@ -268,11 +268,11 @@ define([ //// framework.onContentUpdate(function (newContent) { - CodeMirror.contentUpdate(newContent); var highlightMode = newContent.highlightMode; if (highlightMode && highlightMode !== CodeMirror.highlightMode) { CodeMirror.setMode(highlightMode, evModeChange.fire); } + CodeMirror.contentUpdate(newContent); previewPane.draw(); }); diff --git a/www/common/sframe-common-codemirror.js b/www/common/sframe-common-codemirror.js index f06488abd..b9d14b658 100644 --- a/www/common/sframe-common-codemirror.js +++ b/www/common/sframe-common-codemirror.js @@ -313,6 +313,9 @@ define([ exp.contentUpdate = function (newContent) { var oldDoc = canonicalize($textarea.val()); var remoteDoc = newContent.content; + // setValueAndCursor triggers onLocal, even if we don't make any change to the content + // and it may revert other changes (metadata) + if (oldDoc === remoteDoc) { return; } exp.setValueAndCursor(oldDoc, remoteDoc); };