(feat) reset button
This commit is contained in:
parent
0a9b6f13a7
commit
ca8c439df6
|
@ -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);
|
||||
}
|
||||
});
|
|
@ -34,6 +34,9 @@
|
|||
<button id="run">
|
||||
Run!
|
||||
</button>
|
||||
<button id="reset">
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
<div id='container'></div>
|
||||
<pre id="output" readonly></pre>
|
||||
|
|
Loading…
Reference in New Issue