diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/events.js b/user_config/usr/share/newton/context_path/resources/js/newton/events.js
index 5162210..3ed69fa 100644
--- a/user_config/usr/share/newton/context_path/resources/js/newton/events.js
+++ b/user_config/usr/share/newton/context_path/resources/js/newton/events.js
@@ -4,6 +4,7 @@ window.onload = (eve) => {
loadEditor();
loadPreviewEditor();
loadInitialSession();
+ loadStartingFiles();
}
window.onerror = function(msg, url, line, col, error) {
diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js
index 461d311..78f962e 100644
--- a/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js
+++ b/user_config/usr/share/newton/context_path/resources/js/newton/ui-logic.js
@@ -23,7 +23,7 @@ const loadEditor = () => {
editor.commands.addCommands(editorCommands);
editor.setTheme("ace/theme/one_dark");
-
+
editor.addEventListener("click", (eve) => {
setLabels();
});
@@ -33,6 +33,10 @@ const loadInitialSession = () => {
newSession(null, editor.getSession());
}
+const loadStartingFiles = () => {
+ sendMessage("load_starting_files");
+}
+
const newSession = (eve = null, session = null) => {
let ftype = "buffer";
let fhash = Date.now().toString();
@@ -69,12 +73,27 @@ const updateSession = (fhash, ftype, fname, fpath) => {
aceSessions[fhash]["fpath"] = fpath;
}
-const closeSession = (fhash) => {
- let ftype = aceSessions["ftype"];
- let fpath = aceSessions["fpath"];
+const closeSession = () => {
+ let keys = Object.keys(aceSessions);
+ if (keys.length === 1) {
+ const msg = "Can't close last open buffer...";
+ displayMessage(msg, "warning", 3);
+ return;
+ }
- delete aceSessions[fhash];
- sendMessage("close", ftype, fhash, fpath, "");
+ let index = keys.indexOf(currentSession);
+ let fhash = keys[index + 1];
+ if ( !isNotNullOrUndefined(fhash) ) {
+ fhash = keys[index - 1];
+ }
+
+ let ftype = aceSessions[fhash]["ftype"];
+ let session = aceSessions[fhash]["session"];
+
+ delete aceSessions[currentSession]["session"];
+ delete aceSessions[currentSession];
+
+ setSession(ftype, fhash, session);
}
const removeSession = (fhash) => {
@@ -138,7 +157,7 @@ const listOpenBuffers = () => {
previewEditor.setSession(session);
if (ftype !== "buffer") {
- previewEditor.session.setMode("ace/mode/" + ftype);
+ previewEditor.session.setMode(`ace/mode/${ftype}`);
}
previewSel.classList.add("bg-info");
@@ -208,4 +227,3 @@ const toggleLineHighlight = () => {
highlightLine = !highlightLine;
editor.setHighlightActiveLine(highlightLine);
}
-
diff --git a/user_config/usr/share/newton/context_path/resources/js/newton/utils.js b/user_config/usr/share/newton/context_path/resources/js/newton/utils.js
index c778273..e6d361b 100644
--- a/user_config/usr/share/newton/context_path/resources/js/newton/utils.js
+++ b/user_config/usr/share/newton/context_path/resources/js/newton/utils.js
@@ -27,7 +27,13 @@ const displayMessage = (message, type, timeout, msgWindow = "page-alert-zone") =
}
}
-const sendMessage = (topic, ftype, fhash, fpath, content) => {
+const sendMessage = (topic = null, ftype = "", fhash = "", fpath = "", content = "") => {
+ if ( !isNotNullOrUndefined(topic) ) {
+ const msg = "No 'topic' passed in 'sendMessage' method...";
+ displayMessage(msg, "danger");
+ return;
+ }
+
const messageBody = {
"topic": topic,
"ftype": ftype,