Commit e52dc6c8 authored by Jérome Perrin's avatar Jérome Perrin

sql_browser: backup editor content in a textarea

Browsers (at least chrome) saves the textarea content and restore it
when going back or resurecting a closed tab, which prevents loosing
unsaved work.
This browser feature does not work in "rich" javascript
editors, but this trick of syncronizing the rich editor content to a
hidden textarea seem to makes it work.
parent 7941e90f
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
$(function() { $(function() {
let editor_backup = document.querySelector("textarea[name='editor_backup']");
editor = monaco.editor.create( editor = monaco.editor.create(
document.querySelector('#query'), document.querySelector('#query'),
{ {
...@@ -108,6 +109,14 @@ ...@@ -108,6 +109,14 @@
editor.getModel(), editor.getModel(),
"sql" "sql"
); );
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
editor.getModel().setValue(editor_backup.value);
}
});
editor.getModel().onDidChangeContent(event => {
editor_backup.value = editor.getValue();
});
editor.addAction({ editor.addAction({
id: 'execute-query', id: 'execute-query',
label: 'Execute Query', label: 'Execute Query',
...@@ -190,6 +199,9 @@ ...@@ -190,6 +199,9 @@
<div style="display: none"> <div style="display: none">
<pre id="config_json"></pre> <pre id="config_json"></pre>
</div> </div>
<div style="display: none">
<textarea name="editor_backup"></textarea>
</div>
</body> </body>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment