Commit 0d532f00 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Save to storage at most every 5 seconds

parent 98fb006d
...@@ -452,20 +452,31 @@ var run = function () { ...@@ -452,20 +452,31 @@ var run = function () {
var previousInput = '' var previousInput = ''
var compileTimeout = null var compileTimeout = null
var saveTimeout = null
function editorOnChange () { function editorOnChange () {
var input = editor.getValue() var input = editor.getValue()
// save contents
editor.setCacheFileContent(input)
if (input === '') { // if there's no change, don't do anything
if (input === previousInput) {
return return
} }
previousInput = input
if (input === previousInput) { // fire storage update
// NOTE: save at most once per 5 seconds
if (saveTimeout) {
window.clearTimeout(saveTimeout)
}
saveTimeout = window.setTimeout(function () {
var input = editor.getValue()
editor.setCacheFileContent(input)
}, 5000)
// special case: there's nothing else to do
if (input === '') {
return return
} }
previousInput = input
if (!autoCompile) { if (!autoCompile) {
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment