diff --git a/CHANGELOG.md b/CHANGELOG.md index aa754fe..6c60671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix cursor displayed position on activity ([#183]). - Checkboxes always have bullets in front of them ([#136]). +- Save the text only when modifying the content of the easymde instance (Thanks to [@firm1], [#181]). ## [2.10.1] - 2020-04-06 ### Fixed diff --git a/src/js/easymde.js b/src/js/easymde.js index 845afb7..7a03940 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2039,7 +2039,13 @@ EasyMDE.prototype.render = function (el) { this.gui.statusbar = this.createStatusbar(); } if (options.autosave != undefined && options.autosave.enabled === true) { - this.autosave(); + this.autosave(); // use to load localstorage content + this.codemirror.on('change', function () { + clearTimeout(self._autosave_timeout); + self._autosave_timeout = setTimeout(function () { + self.autosave(); + }, self.options.autosave.submit_delay || self.options.autosave.delay || 1000); + }); } this.gui.sideBySide = this.createSideBySide(); @@ -2071,6 +2077,7 @@ function isLocalStorageAvailable() { } EasyMDE.prototype.autosave = function () { + console.log('save'); if (isLocalStorageAvailable()) { var easyMDE = this; @@ -2086,11 +2093,6 @@ EasyMDE.prototype.autosave = function () { easyMDE.autosaveTimeoutId = undefined; localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId); - - // Restart autosaving in case the submit will be cancelled down the line - setTimeout(function () { - easyMDE.autosave(); - }, easyMDE.options.autosave.submit_delay || easyMDE.options.autosave.delay || 10000); }); } @@ -2121,10 +2123,6 @@ EasyMDE.prototype.autosave = function () { el.innerHTML = save + dd; } - - this.autosaveTimeoutId = setTimeout(function () { - easyMDE.autosave(); - }, this.options.autosave.delay || 10000); } else { console.log('EasyMDE: localStorage not available, cannot autosave'); }