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 @@
$(function() {
let editor_backup = document.querySelector("textarea[name='editor_backup']");
editor = monaco.editor.create(
document.querySelector('#query'),
{
......@@ -108,6 +109,14 @@
editor.getModel(),
"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({
id: 'execute-query',
label: 'Execute Query',
......@@ -190,6 +199,9 @@
<div style="display: none">
<pre id="config_json"></pre>
</div>
<div style="display: none">
<textarea name="editor_backup"></textarea>
</div>
</body>
......
  • I'm not sure we can write zelenium test for this, maybe using javascript window.history.back() and wait for a delay - I don't remember if I tried, this is another "proof of concept" commit 

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