[fix] persist forms
This commit is contained in:
parent
4ccc684f89
commit
c4bf51233a
1 changed files with 62 additions and 31 deletions
|
@ -22,6 +22,7 @@ window.addEventListener('load', () => {
|
||||||
}
|
}
|
||||||
$("iServer").value = svr;
|
$("iServer").value = svr;
|
||||||
view.setState(lsp.EditorState.create({ doc: doc, extensions: lsp.baseExts }));
|
view.setState(lsp.EditorState.create({ doc: doc, extensions: lsp.baseExts }));
|
||||||
|
formFromStore('fSettings');
|
||||||
connect();
|
connect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,35 +52,35 @@ $("symbols2").onclick = e => {
|
||||||
.then(r => {
|
.then(r => {
|
||||||
console.log("symbols", r)
|
console.log("symbols", r)
|
||||||
$("symPanel").open = true;
|
$("symPanel").open = true;
|
||||||
const icons=[
|
const icons = [
|
||||||
'symbol-file' ,
|
'symbol-file',
|
||||||
'symbol-class' ,
|
'symbol-class',
|
||||||
'symbol-namespace' ,
|
'symbol-namespace',
|
||||||
'symbol-structure' ,
|
'symbol-structure',
|
||||||
'symbol-class' ,
|
'symbol-class',
|
||||||
'symbol-method' ,
|
'symbol-method',
|
||||||
'symbol-property' ,
|
'symbol-property',
|
||||||
'symbol-field' ,
|
'symbol-field',
|
||||||
'symbol-method-arrow' ,
|
'symbol-method-arrow',
|
||||||
'symbol-enum' ,
|
'symbol-enum',
|
||||||
'symbol-interface' ,
|
'symbol-interface',
|
||||||
'symbol-method' ,
|
'symbol-method',
|
||||||
'symbol-variable' ,
|
'symbol-variable',
|
||||||
'symbol-constant' ,
|
'symbol-constant',
|
||||||
'symbol-string' ,
|
'symbol-string',
|
||||||
'symbol-numeric' ,
|
'symbol-numeric',
|
||||||
'symbol-boolean' ,
|
'symbol-boolean',
|
||||||
'symbol-array' ,
|
'symbol-array',
|
||||||
'symbol-structure' ,
|
'symbol-structure',
|
||||||
'symbol-key' ,
|
'symbol-key',
|
||||||
'dash' ,
|
'dash',
|
||||||
'symbol-enum-member' ,
|
'symbol-enum-member',
|
||||||
'symbol-misc' ,
|
'symbol-misc',
|
||||||
'symbol-event' ,
|
'symbol-event',
|
||||||
'symbol-operator' ,
|
'symbol-operator',
|
||||||
'symbol-parameter'
|
'symbol-parameter'
|
||||||
];
|
];
|
||||||
$("symList").setData(r,icons);
|
$("symList").setData(r, icons);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -128,13 +129,17 @@ $("load").onchange = e => {
|
||||||
|
|
||||||
function updateSettings(event) {
|
function updateSettings(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log("COPTS",lsp.curOpts);
|
const form = $('fSettings');
|
||||||
const opts={lineWrap: $("lineWrap").checked,
|
console.log("ser..", formSerialize(form))
|
||||||
minimap:$("minimap").checked
|
console.log("COPTS", lsp.curOpts);
|
||||||
|
const opts = {
|
||||||
|
lineWrap: $("lineWrap").checked,
|
||||||
|
minimap: $("minimap").checked
|
||||||
}
|
}
|
||||||
console.log(opts)
|
console.log(opts)
|
||||||
lsp.updateCompartment(opts);
|
lsp.updateCompartment(opts);
|
||||||
$('popSettings').hidePopover();
|
$('popSettings').hidePopover();
|
||||||
|
formToStore("fSettings");
|
||||||
};
|
};
|
||||||
|
|
||||||
$("fSettings").addEventListener("submit", updateSettings);
|
$("fSettings").addEventListener("submit", updateSettings);
|
||||||
|
@ -195,3 +200,29 @@ function log(rpc) {
|
||||||
$("traffic").insertBefore(li, $("traffic").firstChild)
|
$("traffic").insertBefore(li, $("traffic").firstChild)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function formFromStore(name) {
|
||||||
|
let v = localStorage.getItem(name)
|
||||||
|
if (!!v) formDeserialize($(name), v);
|
||||||
|
};
|
||||||
|
|
||||||
|
function formToStore(name) {
|
||||||
|
localStorage.setItem(name, formSerialize($(name)));
|
||||||
|
};
|
||||||
|
|
||||||
|
function formSerialize(form) {
|
||||||
|
const data = new FormData(form);
|
||||||
|
//https://stackoverflow.com/a/44033425/1869660
|
||||||
|
return new URLSearchParams(data).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formDeserialize(form, data) {
|
||||||
|
const entries = (new URLSearchParams(data)).entries();
|
||||||
|
for (const [key, val] of entries) {
|
||||||
|
//http://javascript-coder.com/javascript-form/javascript-form-value.phtml
|
||||||
|
const input = form.elements[key];
|
||||||
|
switch (input.type) {
|
||||||
|
case 'checkbox': input.checked = !!val; break;
|
||||||
|
default: input.value = val; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue