diff --git a/index.html b/index.html
index f9bfe86..6133ceb 100644
--- a/index.html
+++ b/index.html
@@ -11,6 +11,55 @@
+
diff --git a/main.js b/main.js
index 36e3325..0744252 100644
--- a/main.js
+++ b/main.js
@@ -23,6 +23,7 @@ $.get({
}
});
+// language selector
let langaugeSelector = $("#language");
langaugeSelector.change(() => {
let selected = langaugeSelector.val();
@@ -38,6 +39,13 @@ for (key in languages) {
langaugeSelector.append(``);
}
+// theme selector
+let themeSelector = $("#theme");
+themeSelector.change(() => {
+ setTheme(themeSelector.val());
+ save();
+});
+
// setup
function setup(data, mime) {
let el = document.getElementById("editor");
@@ -259,6 +267,7 @@ function load() {
.then((val) => {
loadInvalids(val[filePath]);
loadCursor(val[filePath]);
+ loadTheme(val[filePath]);
});
}
@@ -266,6 +275,7 @@ function save() {
let obj = {};
saveInvalids(obj);
saveCursor(obj);
+ saveTheme(obj);
localforage.getItem(repo)
.then((val) => {
if (!val) val = {};
@@ -280,10 +290,10 @@ function save() {
});
}
-function loadInvalids(val) {
- if (val && val.invalids) {
+function loadInvalids(obj) {
+ if (obj && obj.invalids) {
editor.operation(() => { // buffer all DOM changes together b/c performance
- val.invalids.forEach(markInvalid);
+ obj.invalids.forEach(markInvalid);
});
}
}
@@ -307,6 +317,17 @@ function saveInvalids(obj) {
obj.invalids = serialized;
}
+function loadTheme(obj) {
+ if (obj && obj.theme) {
+ themeSelector.val(obj.theme);
+ setTheme(obj.theme);
+ }
+}
+
+function saveTheme(obj) {
+ obj.theme = themeSelector.val();
+}
+
function loadCursor(val) {
editor.setCursor(val && val.cursor ? val.cursor : { line: 0, ch: 0 });
}
@@ -315,6 +336,13 @@ function saveCursor(obj) {
obj.cursor = editor.getCursor();
}
+function setTheme(theme) {
+ if (theme != "default") {
+ $("head").append(``);
+ }
+ editor.setOption("theme", theme);
+}
+
String.prototype.hasOnlyWhiteSpaceBeforeIndex = function(index) {
return this.substring(index) == this.trim();
};