[add] server save/default
This commit is contained in:
parent
433a2c54a7
commit
532580273b
2 changed files with 36 additions and 27 deletions
|
@ -112,7 +112,7 @@
|
|||
</header>
|
||||
<div class="modal-body">
|
||||
<div id="state">🔴</div>
|
||||
<input id="iServer" type="text" value="ws://localhost:3000/ws/lsp" style="width:25em" />
|
||||
<input id="iServer" type="text" style="width:25em" />
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="connect">connect</button>
|
||||
|
|
|
@ -11,10 +11,15 @@ function $(id){ return document.getElementById(id) };
|
|||
// Load saved content from localStorage when the page loads
|
||||
window.addEventListener('load', () => {
|
||||
const savedText = localStorage.getItem('code');
|
||||
if (savedText) {
|
||||
doc = savedText;
|
||||
if (savedText) doc = savedText;
|
||||
let svr = localStorage.getItem('lsp');
|
||||
if (!svr) {
|
||||
let x = new URL(window.location.href);
|
||||
x.protocol = "ws";
|
||||
x.pathname = "ws/lsp"
|
||||
svr = x.href;
|
||||
}
|
||||
|
||||
$("iServer").value = svr;
|
||||
view.setState(lsp.EditorState.create({ doc: doc, extensions: lsp.baseExts }));
|
||||
connect();
|
||||
});
|
||||
|
@ -23,6 +28,7 @@ window.addEventListener('load', () => {
|
|||
window.addEventListener('beforeunload', () => {
|
||||
const doc = view.state.doc.toString();
|
||||
localStorage.setItem('code', doc);
|
||||
localStorage.setItem('lsp', $("iServer").value);
|
||||
});
|
||||
|
||||
$("connect").onclick = e => { e.preventDefault(); connect() };
|
||||
|
@ -80,10 +86,13 @@ function connect() {
|
|||
onChange: (content, state) => {
|
||||
console.log('Debounced change detected:');
|
||||
client.sync();
|
||||
}})
|
||||
}
|
||||
})
|
||||
|
||||
view.dispatch({ effects: lsp.StateEffect.appendConfig.of(
|
||||
[lsp.linter(null, {autoPanel:true}),...extLsp,up]) })
|
||||
view.dispatch({
|
||||
effects: lsp.StateEffect.appendConfig.of(
|
||||
[lsp.linter(null, { autoPanel: true }), ...extLsp, up])
|
||||
})
|
||||
})
|
||||
.catch(r => { connectStatus(false); alert("connection failed: " + server) });
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue