From d30d9b7d00ecb13f7d10c40fcd8233a91c88be1b Mon Sep 17 00:00:00 2001 From: Wes Cossick Date: Sat, 5 Dec 2015 00:31:27 -0600 Subject: [PATCH] Fix initial value overwriting autosaved value --- src/js/simplemde.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/js/simplemde.js b/src/js/simplemde.js index f86f600..352cf8d 100644 --- a/src/js/simplemde.js +++ b/src/js/simplemde.js @@ -941,7 +941,7 @@ function SimpleMDE(options) { // The codemirror component is only available after rendering // so, the setter for the initialValue can only run after // the element has been rendered - if(options.initialValue) { + if(options.initialValue && (!this.options.autosave || this.options.autosave.foundSavedValue !== true)) { this.value(options.initialValue); } } @@ -1081,8 +1081,10 @@ SimpleMDE.prototype.autosave = function() { } if(this.options.autosave.loaded !== true) { - if(typeof localStorage.getItem("smde_" + this.options.autosave.uniqueId) == "string" && localStorage.getItem("smde_" + this.options.autosave.uniqueId) != "") + if(typeof localStorage.getItem("smde_" + this.options.autosave.uniqueId) == "string" && localStorage.getItem("smde_" + this.options.autosave.uniqueId) != "") { this.codemirror.setValue(localStorage.getItem("smde_" + this.options.autosave.uniqueId)); + this.options.autosave.foundSavedValue = true; + } this.options.autosave.loaded = true; }