diff --git a/static/script/editor.js b/static/script/editor.js index 92f7e7f..a258823 100644 --- a/static/script/editor.js +++ b/static/script/editor.js @@ -15,15 +15,28 @@ require(["vs/editor/editor.main"], function () { /** @type {string[]} */ const supported_langs = get_langs(); + let cache_key = 'sandy-cached-code'; + const storage = window.localStorage; + let editor = monaco.editor.create(document.getElementById('container'), { - value: '# put code here', + value: storage.getItem(cache_key) ?? '# put code here', language: init_lang, theme: 'vs-dark' }); - editor.addListener('didType', () => { + function upd_code() { window.code = editor.getValue(); - }); + storage.setItem(cache_key, window.code); + } + function timer_code() { + setTimeout(() => { + timer_code() + upd_code(); + }, 500); + } + + editor.addListener('didType', () => upd_code); + timer_code(); monaco.languages.getLanguages().forEach(x => { if (supported_langs.indexOf(x.id) === -1) return