(feat) cache the selected language as well
This commit is contained in:
parent
5b68507e97
commit
0a9b6f13a7
|
@ -11,22 +11,24 @@ let proxy = URL.createObjectURL(new Blob([`
|
||||||
|
|
||||||
require(["vs/editor/editor.main"], function () {
|
require(["vs/editor/editor.main"], function () {
|
||||||
|
|
||||||
let init_lang = 'python';
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
const supported_langs = get_langs();
|
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 storage = window.localStorage;
|
||||||
|
|
||||||
|
const init_lang = storage.getItem(lang_key) ?? 'python';
|
||||||
|
|
||||||
let editor = monaco.editor.create(document.getElementById('container'), {
|
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,
|
language: init_lang,
|
||||||
theme: 'vs-dark'
|
theme: 'vs-dark'
|
||||||
});
|
});
|
||||||
|
|
||||||
function upd_code() {
|
function upd_code() {
|
||||||
window.code = editor.getValue();
|
window.code = editor.getValue();
|
||||||
storage.setItem(cache_key, window.code);
|
storage.setItem(code_key, window.code);
|
||||||
}
|
}
|
||||||
function timer_code() {
|
function timer_code() {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -52,7 +54,9 @@ require(["vs/editor/editor.main"], function () {
|
||||||
|
|
||||||
document.getElementById('lang').onchange = (e) => {
|
document.getElementById('lang').onchange = (e) => {
|
||||||
e = e.target;
|
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) => {
|
document.getElementById('run').onclick = (e) => {
|
||||||
|
|
Loading…
Reference in New Issue