diff --git a/src/web/BindingsWaiter.js b/src/web/BindingsWaiter.js index 2454ed59..802590b8 100644 --- a/src/web/BindingsWaiter.js +++ b/src/web/BindingsWaiter.js @@ -23,36 +23,40 @@ const BindingsWaiter = function (app, manager) { * @param {event} e */ BindingsWaiter.prototype.parseInput = function(e) { - let modKey = e.altKey; - if (this.app.options.useMetaKey) modKey = e.metaKey; + const modKey = this.app.options.useMetaKey ? e.metaKey : e.altKey; + if (e.ctrlKey && modKey) { let elem; switch (e.code) { - case "KeyF": + case "KeyF": // Focus search e.preventDefault(); - document.getElementById("search").focus(); // Focus search + document.getElementById("search").focus(); break; - case "KeyI": + case "KeyI": // Focus input e.preventDefault(); - document.getElementById("input-text").focus(); // Focus input + document.getElementById("input-text").focus(); break; - case "KeyO": + case "KeyO": // Focus output e.preventDefault(); - document.getElementById("output-text").focus(); // Focus output + document.getElementById("output-text").focus(); break; - case "Period": + case "Period": // Focus next operation + e.preventDefault(); try { - elem = document.activeElement.closest(".operation"); + elem = document.activeElement.closest(".operation") || document.querySelector("#rec-list .operation"); if (elem.parentNode.lastChild === elem) { - elem.parentNode.firstChild.querySelectorAll(".arg")[0].focus(); // if operation is last in recipe, loop around to the top operation's first argument + // If operation is last in recipe, loop around to the top operation's first argument + elem.parentNode.firstChild.querySelectorAll(".arg")[0].focus(); } else { - elem.nextSibling.querySelectorAll(".arg")[0].focus(); //focus first argument of next operation + // Focus first argument of next operation + elem.nextSibling.querySelectorAll(".arg")[0].focus(); } } catch (e) { // do nothing, just don't throw an error } break; - case "KeyB": + case "KeyB": // Set breakpoint + e.preventDefault(); try { elem = document.activeElement.closest(".operation").querySelectorAll(".breakpoint")[0]; if (elem.getAttribute("break") === "false") { @@ -67,7 +71,8 @@ BindingsWaiter.prototype.parseInput = function(e) { // do nothing, just don't throw an error } break; - case "KeyD": + case "KeyD": // Disable operation + e.preventDefault(); try { elem = document.activeElement.closest(".operation").querySelectorAll(".disable-icon")[0]; if (elem.getAttribute("disabled") === "false") { @@ -85,29 +90,36 @@ BindingsWaiter.prototype.parseInput = function(e) { // do nothing, just don't throw an error } break; - case "Space": - this.app.bake(); // bake the recipe + case "Space": // Bake + e.preventDefault(); + this.app.bake(); break; - case "Quote": - this.app.bake(true); // step through the recipe + case "Quote": // Step through + e.preventDefault(); + this.app.bake(true); break; - case "KeyC": - this.manager.recipe.clearRecipe(); // clear recipe + case "KeyC": // Clear recipe + e.preventDefault(); + this.manager.recipe.clearRecipe(); break; - case "KeyS": - this.manager.output.saveClick(); // save output to file + case "KeyS": // Save output to file + e.preventDefault(); + this.manager.output.saveClick(); break; - case "KeyL": - this.manager.controls.loadClick(); // load a recipe + case "KeyL": // Load recipe + e.preventDefault(); + this.manager.controls.loadClick(); break; - case "KeyM": - this.manager.controls.switchClick(); // switch input & output + case "KeyM": // Switch input and output + e.preventDefault(); + this.manager.output.switchClick(); break; default: - if (e.code.match(/Digit[0-9]/g)) { + if (e.code.match(/Digit[0-9]/g)) { // Select nth operation e.preventDefault(); try { - document.querySelector(`li:nth-child(${e.code.substr(-1)}) .arg`).focus(); // select the first argument of the operation corresponding to the number pressed + // Select the first argument of the operation corresponding to the number pressed + document.querySelector(`li:nth-child(${e.code.substr(-1)}) .arg`).focus(); } catch (e) { // do nothing, just don't throw an error } @@ -117,6 +129,7 @@ BindingsWaiter.prototype.parseInput = function(e) { } }; + /** * Updates keybinding list when metaKey option is toggled * @@ -149,12 +162,12 @@ BindingsWaiter.prototype.updateKeybList = function() { Ctrl+${modMac}+o - Place cursor in first argument field
of the next operation in the recipe + Place cursor in first argument field of the next operation in the recipe Ctrl+${modWinLin}+. Ctrl+${modMac}+. - Place cursor in first argument field
of the nth operation in the recipe + Place cursor in first argument field of the nth operation in the recipe Ctrl+${modWinLin}+[1-9] Ctrl+${modMac}+[1-9] diff --git a/src/web/Manager.js b/src/web/Manager.js index c9ae1eb5..2b44e6d2 100755 --- a/src/web/Manager.js +++ b/src/web/Manager.js @@ -77,8 +77,8 @@ Manager.prototype.setup = function() { this.worker.registerChefWorker(); this.recipe.initialiseOperationDragNDrop(); this.controls.autoBakeChange(); - this.seasonal.load(); this.bindings.updateKeybList(); + this.seasonal.load(); }; @@ -92,6 +92,7 @@ Manager.prototype.initialiseEventListeners = function() { window.addEventListener("focus", this.window.windowFocus.bind(this.window)); window.addEventListener("statechange", this.app.stateChange.bind(this.app)); window.addEventListener("popstate", this.app.popState.bind(this.app)); + // Controls document.getElementById("bake").addEventListener("click", this.controls.bakeClick.bind(this.controls)); document.getElementById("auto-bake").addEventListener("change", this.controls.autoBakeChange.bind(this.controls)); @@ -162,16 +163,14 @@ Manager.prototype.initialiseEventListeners = function() { document.getElementById("reset-options").addEventListener("click", this.options.resetOptionsClick.bind(this.options)); $(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.switchChange.bind(this.options)); $(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox", this.options.setWordWrap.bind(this.options)); + $(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox#useMetaKey", this.bindings.updateKeybList.bind(this.bindings)); this.addDynamicListener(".option-item input[type=number]", "keyup", this.options.numberChange, this.options); this.addDynamicListener(".option-item input[type=number]", "change", this.options.numberChange, this.options); this.addDynamicListener(".option-item select", "change", this.options.selectChange, this.options); document.getElementById("theme").addEventListener("change", this.options.themeChange.bind(this.options)); - //Keybindings - window.addEventListener("keydown", this.bindings.parseInput.bind(this.bindings)); - $(document).on("switchChange.bootstrapSwitch", ".option-item input:checkbox#useMetaKey", this.bindings.updateKeybList.bind(this.bindings)); - // Misc + window.addEventListener("keydown", this.bindings.parseInput.bind(this.bindings)); document.getElementById("alert-close").addEventListener("click", this.app.alertCloseClick.bind(this.app)); }; diff --git a/src/web/html/index.html b/src/web/html/index.html index b1adfad7..66dfcc80 100755 --- a/src/web/html/index.html +++ b/src/web/html/index.html @@ -328,7 +328,7 @@
- +
@@ -486,7 +486,7 @@

It’s the Cyber Swiss Army Knife.

-
+