(feat) reset button

This commit is contained in:
b1ek 2024-02-19 16:34:29 +10:00
parent 0a9b6f13a7
commit ca8c439df6
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 18 additions and 1 deletions

View File

@ -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);
}
});

View File

@ -34,6 +34,9 @@
<button id="run">
Run!
</button>
<button id="reset">
Reset
</button>
</div>
<div id='container'></div>
<pre id="output" readonly></pre>