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,40 +1833,58 @@ 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
switch(key) {
case config.shortcuts.playAnimation:
console.log("Spacebar pressed") console.log("Spacebar pressed")
playPause() playPause()
} else if (e.key == config.shortcuts.new && mod == true) { break;
case config.shortcuts.new:
newFile() newFile()
} else if (e.key == config.shortcuts.save && mod == true) { break;
case config.shortcuts.save:
save() save()
} else if (e.key == config.shortcuts.saveAs && mod == true) { break;
case config.shortcuts.saveAs:
saveAs() saveAs()
} else if (e.key == config.shortcuts.open && mod == true) { break;
case config.shortcuts.open:
open() open()
} else if (e.key == config.shortcuts.quit && mod == true) { break;
case config.shortcuts.quit:
quit() quit()
} else if (e.key == config.shortcuts.undo && mod == true) { break;
case config.shortcuts.undo:
undo() undo()
} else if (e.key == config.shortcuts.redo && mod == true) { break;
case config.shortcuts.redo:
redo() redo()
} else if (e.key == config.shortcuts.copy && mod == true) { break;
case config.shortcuts.copy:
copy() copy()
} else if (e.key == config.shortcuts.paste && mod == true) { break;
case config.shortcuts.paste:
paste() paste()
} else if (e.key == config.shortcuts.delete) { break;
case config.shortcuts.delete:
delete_action() delete_action()
} else if (e.key == config.shortcuts.group && mod == true) { break;
case config.shortcuts.group:
actions.group.create() actions.group.create()
} else if (e.key == config.shortcuts.zoomIn && mod == true) { break;
case config.shortcuts.zoomIn:
zoomIn() zoomIn()
} else if (e.key == config.shortcuts.zoomOut && mod == true) { break;
case config.shortcuts.zoomOut:
zoomOut() zoomOut()
} break;
else if (e.key == "ArrowRight") { // TODO: put these in shortcuts
if (mod == true) { case "<mod>ArrowRight":
advanceFrame() advanceFrame()
} else if (context.selection) { e.preventDefault()
break;
case "ArrowRight":
if (context.selection) {
context.activeObject.currentFrame.saveState() context.activeObject.currentFrame.saveState()
for (let item of context.selection) { for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].x += 1 context.activeObject.currentFrame.keys[item.idx].x += 1
@ -1875,11 +1893,12 @@ window.addEventListener("keydown", (e) => {
updateUI() updateUI()
} }
e.preventDefault() e.preventDefault()
} break;
else if (e.key == "ArrowLeft") { case "<mod>ArrowLeft":
if (mod == true) {
decrementFrame() decrementFrame()
} else if (context.selection) { break;
case "ArrowLeft":
if (context.selection) {
context.activeObject.currentFrame.saveState() context.activeObject.currentFrame.saveState()
for (let item of context.selection) { for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].x -= 1 context.activeObject.currentFrame.keys[item.idx].x -= 1
@ -1888,11 +1907,9 @@ window.addEventListener("keydown", (e) => {
updateUI() updateUI()
} }
e.preventDefault() e.preventDefault()
} break;
else if (e.key == "ArrowUp") { case "ArrowUp":
if (mod == true) { if (context.selection) {
// no action yet for ctrl+up
} else if (context.selection) {
context.activeObject.currentFrame.saveState() context.activeObject.currentFrame.saveState()
for (let item of context.selection) { for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].y -= 1 context.activeObject.currentFrame.keys[item.idx].y -= 1
@ -1901,11 +1918,9 @@ window.addEventListener("keydown", (e) => {
updateUI() updateUI()
} }
e.preventDefault() e.preventDefault()
} break;
else if (e.key == "ArrowDown") { case "ArrowDown":
if (mod == true) { if (context.selection) {
// no action yet for ctrl+down
} else if (context.selection) {
context.activeObject.currentFrame.saveState() context.activeObject.currentFrame.saveState()
for (let item of context.selection) { for (let item of context.selection) {
context.activeObject.currentFrame.keys[item.idx].y += 1 context.activeObject.currentFrame.keys[item.idx].y += 1
@ -1914,6 +1929,9 @@ window.addEventListener("keydown", (e) => {
updateUI() updateUI()
} }
e.preventDefault() e.preventDefault()
break;
default:
break
} }
}) })