Skip to content

Commit

Permalink
Autosave when running script
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacehuhn committed Nov 16, 2019
1 parent 6678e17 commit e568f69
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ function getEditorContent() {
return E("editor").value;
}

function saveFile() {
var content = getEditorContent();
if (!content.endsWith("\n")) content = content + "\n";

ws_send_write(getEditorFileName(), content);

E("editorinfo").innerHTML = "saved";
}

// ===== WebSocket Actions ===== //
function check_status() {
if (current_status.includes("running")) {
Expand All @@ -55,6 +64,7 @@ function ws_send_format() {
}

function ws_send_run(fileName) {
if (E("editorinfo").innerHTML != "saved") saveFile();
ws_send("run \"" + fixFileName(fileName) + "\"", log_ws);
start_status_interval();
}
Expand Down Expand Up @@ -231,12 +241,7 @@ window.addEventListener("load", function() {
};

E("editorSave").onclick = function() {
var content = getEditorContent();
if (!content.endsWith("\n")) content = content + "\n";

ws_send_write(getEditorFileName(), content);

E("editorinfo").innerHTML = "saved";
saveFile();
};

E("editorDelete").onclick = function() {
Expand Down

0 comments on commit e568f69

Please sign in to comment.