diff --git a/static/script/editor.js b/static/script/editor.js index 78fe8ba..734df06 100644 --- a/static/script/editor.js +++ b/static/script/editor.js @@ -19,13 +19,16 @@ require(["vs/editor/editor.main"], function () { const storage = window.localStorage; const init_lang = storage.getItem(lang_key) ?? 'python'; + const init_code = storage.getItem(code_key) ?? '# put code here'; let editor = monaco.editor.create(document.getElementById('container'), { - value: storage.getItem(code_key) ?? '# put code here', + value: init_code, language: init_lang, theme: 'vs-dark' }); + let model = editor.getModel(); + function upd_code() { window.code = editor.getValue(); storage.setItem(code_key, window.code); @@ -62,4 +65,15 @@ require(["vs/editor/editor.main"], function () { document.getElementById('run').onclick = (e) => { executeCode(window.code, editor.getModel().getLanguageIdentifier().language) } + + document.getElementById('reset').onclick = (_) => { + storage.removeItem(lang_key); + storage.removeItem(code_key); + + lang = 'python'; + monaco.editor.setModelLanguage(editor.getModel(), 'python'); + + window.code = init_code; + model.setValue(init_code); + } }); \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 443a0cd..b895904 100644 --- a/templates/index.html +++ b/templates/index.html @@ -34,6 +34,9 @@ +