diff options
author | Matthew Sotoudeh <matthewsot@outlook.com> | 2017-07-31 16:00:11 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthewsot@outlook.com> | 2017-07-31 16:00:11 -0700 |
commit | 3f4946338fc50ae324116f97e22a80e5d18457e1 (patch) | |
tree | 28e0d346d1a72636ca9de6c36372621fe8f65d6b | |
parent | 07e017d83b2743ee63689d640df6189b57e1a967 (diff) |
keyboard shortcuts
-rw-r--r-- | content/scripts/editor.js | 23 | ||||
-rw-r--r-- | content/scripts/open-save.js | 21 |
2 files changed, 42 insertions, 2 deletions
diff --git a/content/scripts/editor.js b/content/scripts/editor.js index d0cc59f..b16e39f 100644 --- a/content/scripts/editor.js +++ b/content/scripts/editor.js @@ -92,7 +92,28 @@ editor.setOption("extraKeys", { }, "Ctrl-S": function (cm) { window.save(); - } + }, + "Cmd-S": function (cm) { + window.save(); + }, + "Ctrl-Shift-S": function (cm) { + window.save(); + }, + "Cmd-Shift-S": function (cm) { + window.save(); + }, + "Ctrl-O": function (cm) { + window.open(); + }, + "Cmd-O": function (cm) { + window.open(); + }, + "Ctrl-N": function (cm) { + window.newFile(); + }, + "Cmd-N": function (cm) { + window.newFile(); + }, }); if (proj.length > 0) { diff --git a/content/scripts/open-save.js b/content/scripts/open-save.js index eaa603f..d8da8fe 100644 --- a/content/scripts/open-save.js +++ b/content/scripts/open-save.js @@ -7,7 +7,7 @@ window.fileName = null; var extension = { "javascript": "js", "yaepl": "yaepl" }[window.lang]; var filter = { name: window.lang + " files", extensions: [extension] }; -document.getElementById("open").onclick = function () { +window.open = function () { dialog.showOpenDialog({ filters: [ filter] }, function (fileNames) { if (fileNames === undefined) return; @@ -18,9 +18,28 @@ document.getElementById("open").onclick = function () { }); }; +document.getElementById("open").onclick = window.open; + +window.newFile = function () { + editor.setValue(""); + term.clear(); + window.fileName = fileName; +}; + +window.saveAs = function () { + dialog.showSaveDialog({ filters: [ filter ] }, + function (fileName) { + if (fileName === undefined) return; + window.fileName = fileName; + window.save(); + }); +}; + window.save = function () { if (window.fileName !== null) { fs.writeFile(window.fileName, editor.getValue(), function (err) {}); + } else { + window.saveAs(); } }; |