From ca8c439df64ea6c2524d5909faf4ea196af1b028 Mon Sep 17 00:00:00 2001 From: b1ek Date: Mon, 19 Feb 2024 16:34:29 +1000 Subject: [PATCH] (feat) reset button --- static/script/editor.js | 16 +++++++++++++++- templates/index.html | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) 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 @@ +