Parameterize keyboard shortcuts

This commit is contained in:
Skyler Lehmkuhl 2024-12-06 02:23:58 -05:00
parent af7e1b8d85
commit b589885ed7
1 changed files with 105 additions and 87 deletions

View File

@ -138,19 +138,19 @@ let config = {
shortcuts: { shortcuts: {
playAnimation: " ", playAnimation: " ",
// undo: "<ctrl>+z" // undo: "<ctrl>+z"
undo: "z", undo: "<mod>z",
redo: "Z", redo: "<mod>Z",
new: "n", new: "<mod>n",
save: "s", save: "<mod>s",
saveAs: "S", saveAs: "<mod>S",
open: "o", open: "<mod>o",
quit: "q", quit: "<mod>q",
copy: "c", copy: "<mod>c",
paste: "v", paste: "<mod>v",
delete: "Backspace", delete: "Backspace",
group: "g", group: "<mod>g",
zoomIn: "+", zoomIn: "<mod>+",
zoomOut: "-", zoomOut: "<mod>-",
} }
} }
@ -1833,87 +1833,105 @@ window.addEventListener("keydown", (e) => {
// } // }
console.log(e) console.log(e)
let mod = macOS ? e.metaKey : e.ctrlKey; let mod = macOS ? e.metaKey : e.ctrlKey;
if (e.key == config.shortcuts.playAnimation) { let key = (mod ? "<mod>" : "") + e.key
console.log("Spacebar pressed") switch(key) {
playPause() case config.shortcuts.playAnimation:
} else if (e.key == config.shortcuts.new && mod == true) { console.log("Spacebar pressed")
newFile() playPause()
} else if (e.key == config.shortcuts.save && mod == true) { break;
save() case config.shortcuts.new:
} else if (e.key == config.shortcuts.saveAs && mod == true) { newFile()
saveAs() break;
} else if (e.key == config.shortcuts.open && mod == true) { case config.shortcuts.save:
open() save()
} else if (e.key == config.shortcuts.quit && mod == true) { break;
quit() case config.shortcuts.saveAs:
} else if (e.key == config.shortcuts.undo && mod == true) { saveAs()
undo() break;
} else if (e.key == config.shortcuts.redo && mod == true) { case config.shortcuts.open:
redo() open()
} else if (e.key == config.shortcuts.copy && mod == true) { break;
copy() case config.shortcuts.quit:
} else if (e.key == config.shortcuts.paste && mod == true) { quit()
paste() break;
} else if (e.key == config.shortcuts.delete) { case config.shortcuts.undo:
delete_action() undo()
} else if (e.key == config.shortcuts.group && mod == true) { break;
actions.group.create() case config.shortcuts.redo:
} else if (e.key == config.shortcuts.zoomIn && mod == true) { redo()
zoomIn() break;
} else if (e.key == config.shortcuts.zoomOut && mod == true) { case config.shortcuts.copy:
zoomOut() copy()
} break;
else if (e.key == "ArrowRight") { case config.shortcuts.paste:
if (mod == true) { paste()
break;
case config.shortcuts.delete:
delete_action()
break;
case config.shortcuts.group:
actions.group.create()
break;
case config.shortcuts.zoomIn:
zoomIn()
break;
case config.shortcuts.zoomOut:
zoomOut()
break;
// TODO: put these in shortcuts
case "<mod>ArrowRight":
advanceFrame() advanceFrame()
} else if (context.selection) { e.preventDefault()
context.activeObject.currentFrame.saveState() break;
for (let item of context.selection) { case "ArrowRight":
context.activeObject.currentFrame.keys[item.idx].x += 1 if (context.selection) {
context.activeObject.currentFrame.saveState()
for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].x += 1
}
actions.editFrame.create(context.activeObject.currentFrame)
updateUI()
} }
actions.editFrame.create(context.activeObject.currentFrame) e.preventDefault()
updateUI() break;
} case "<mod>ArrowLeft":
e.preventDefault()
}
else if (e.key == "ArrowLeft") {
if (mod == true) {
decrementFrame() decrementFrame()
} else if (context.selection) { break;
context.activeObject.currentFrame.saveState() case "ArrowLeft":
for (let item of context.selection) { if (context.selection) {
context.activeObject.currentFrame.keys[item.idx].x -= 1 context.activeObject.currentFrame.saveState()
for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].x -= 1
}
actions.editFrame.create(context.activeObject.currentFrame)
updateUI()
} }
actions.editFrame.create(context.activeObject.currentFrame) e.preventDefault()
updateUI() break;
} case "ArrowUp":
e.preventDefault() if (context.selection) {
} context.activeObject.currentFrame.saveState()
else if (e.key == "ArrowUp") { for (let item of context.selection) {
if (mod == true) { context.activeObject.currentFrame.keys[item.idx].y -= 1
// no action yet for ctrl+up }
} else if (context.selection) { actions.editFrame.create(context.activeObject.currentFrame)
context.activeObject.currentFrame.saveState() updateUI()
for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].y -= 1
} }
actions.editFrame.create(context.activeObject.currentFrame) e.preventDefault()
updateUI() break;
} case "ArrowDown":
e.preventDefault() if (context.selection) {
} context.activeObject.currentFrame.saveState()
else if (e.key == "ArrowDown") { for (let item of context.selection) {
if (mod == true) { context.activeObject.currentFrame.keys[item.idx].y += 1
// no action yet for ctrl+down }
} else if (context.selection) { actions.editFrame.create(context.activeObject.currentFrame)
context.activeObject.currentFrame.saveState() updateUI()
for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].y += 1
} }
actions.editFrame.create(context.activeObject.currentFrame) e.preventDefault()
updateUI() break;
} default:
e.preventDefault() break
} }
}) })