Skip to content

Commit

Permalink
hotkeys update
Browse files Browse the repository at this point in the history
  • Loading branch information
espmaniac authored Jan 5, 2025
1 parent 19d0f7c commit 489b989
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
4 changes: 4 additions & 0 deletions scripts/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Menu {
this.parent = null;
this.level = 0;
this.text = text;


}

addItem(item) {
Expand All @@ -31,6 +33,8 @@ class Menu {

this.element.appendChild(li);



this.submenus.push(item);
}

Expand Down
18 changes: 9 additions & 9 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,21 @@ chooseInductor.addEventListener("click", function() {
});
}

function removeActive() {
for (let i = 0; i < mainTools.children.length; ++i) {
mainTools.children[i].classList.remove("active");
}
for (let i = 0; i < nodeTools.children.length; ++i) {
nodeTools.children[i].classList.remove("active");
}
}

function initTools() {
let mainTools = document.getElementById("mainTools");
let nodeTools = document.getElementById("nodeTools");
let cursorTool = document.getElementById("cursorTool");
let wireTool = document.getElementById("wireTool");

function removeActive() {
for (let i = 0; i < mainTools.children.length; ++i) {
mainTools.children[i].classList.remove("active");
}
for (let i = 0; i < nodeTools.children.length; ++i) {
nodeTools.children[i].classList.remove("active");
}
}

cursorTool.addEventListener("click", function() {
removeActive();
this.classList.add("active");
Expand Down
37 changes: 32 additions & 5 deletions scripts/tool_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,38 @@ var toolmgr = {
},

onKeyDown(event) {
if (event.ctrlKey) {
if (event.shiftKey && event.keyCode === 90)
scheme.redo();
else if (event.keyCode === 90)
scheme.undo();
switch(event.keyCode) {
case 8: case 46:
let elm = (scheme.selectedComponents.length)
? scheme.selectedComponents[0] :
(scheme.selectedWires.length) ? scheme.wires[scheme.selectedWires[0]] : null;

if (elm) scheme.execute(new DeleteElement(elm));

break;

case 83:
removeActive();
let cursorTool = document.getElementById("cursorTool");
cursorTool.classList.add("active");
scheme.tool = "SELECT";

break;

case 87:
removeActive();
let wireTool = document.getElementById("wireTool");
wireTool.classList.add("active");
scheme.tool = "WIRE";
break;

case 90:
if (event.shiftKey && event.ctrlKey)
scheme.redo();
else
scheme.undo();
break;
default: break;
}

}
Expand Down

0 comments on commit 489b989

Please sign in to comment.