(feat) cache the selected language as well

This commit is contained in:
b1ek 2024-02-19 02:56:07 +10:00
parent 5b68507e97
commit 0a9b6f13a7
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 9 additions and 5 deletions

View File

@ -11,22 +11,24 @@ let proxy = URL.createObjectURL(new Blob([`
require(["vs/editor/editor.main"], function () {
let init_lang = 'python';
/** @type {string[]} */
const supported_langs = get_langs();
let cache_key = 'sandy-cached-code';
const code_key = 'sandy-cached-code';
const lang_key = 'sandy-cached-lang';
const storage = window.localStorage;
const init_lang = storage.getItem(lang_key) ?? 'python';
let editor = monaco.editor.create(document.getElementById('container'), {
value: storage.getItem(cache_key) ?? '# put code here',
value: storage.getItem(code_key) ?? '# put code here',
language: init_lang,
theme: 'vs-dark'
});
function upd_code() {
window.code = editor.getValue();
storage.setItem(cache_key, window.code);
storage.setItem(code_key, window.code);
}
function timer_code() {
setTimeout(() => {
@ -52,7 +54,9 @@ require(["vs/editor/editor.main"], function () {
document.getElementById('lang').onchange = (e) => {
e = e.target;
monaco.editor.setModelLanguage(editor.getModel(), e.options[e.selectedIndex].id)
const lang = e.options[e.selectedIndex].id;
monaco.editor.setModelLanguage(editor.getModel(), lang);
storage.setItem(lang_key, lang);
}
document.getElementById('run').onclick = (e) => {