Skip to content

Commit

Permalink
Any keyboard layout for Ctrl + V, Z, Y... (#763)
Browse files Browse the repository at this point in the history
* Any keyboard layout for Ctrl + V, Z, Y...

`if` conditioning changed for better support any keyboard layout for shortcuts

* Format

---------

Co-authored-by: Khachatur Avanesian <jailbreakvideo@gmail.com>
  • Loading branch information
huchenlei and XpucT authored Sep 9, 2024
1 parent 21c3883 commit 23796d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
24 changes: 11 additions & 13 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,10 @@ export class ComfyApp {
}

if (e.type == 'keydown' && !e.repeat) {
const key = e.code

// Ctrl + M mute/unmute
if (e.key === 'm' && (e.metaKey || e.ctrlKey)) {
if (key === 'KeyM' && (e.metaKey || e.ctrlKey)) {
if (this.selected_nodes) {
for (var i in this.selected_nodes) {
if (this.selected_nodes[i].mode === 2) {
Expand All @@ -1299,7 +1301,7 @@ export class ComfyApp {
}

// Ctrl + B bypass
if (e.key === 'b' && (e.metaKey || e.ctrlKey)) {
if (key === 'KeyB' && (e.metaKey || e.ctrlKey)) {
if (this.selected_nodes) {
for (var i in this.selected_nodes) {
if (this.selected_nodes[i].mode === 4) {
Expand All @@ -1314,7 +1316,7 @@ export class ComfyApp {
}

// p pin/unpin
if (e.key === 'p') {
if (key === 'KeyP') {
if (this.selected_nodes) {
for (const i in this.selected_nodes) {
const node = this.selected_nodes[i]
Expand All @@ -1325,7 +1327,7 @@ export class ComfyApp {
}

// Alt + C collapse/uncollapse
if (e.key === 'c' && e.altKey) {
if (key === 'KeyC' && e.altKey) {
if (this.selected_nodes) {
for (var i in this.selected_nodes) {
this.selected_nodes[i].collapse()
Expand All @@ -1335,22 +1337,18 @@ export class ComfyApp {
}

// Ctrl+C Copy
if (e.key === 'c' && (e.metaKey || e.ctrlKey)) {
if (key === 'KeyC' && (e.metaKey || e.ctrlKey)) {
// Trigger onCopy
return true
}

// Ctrl+V Paste
if (
(e.key === 'v' || e.key == 'V') &&
(e.metaKey || e.ctrlKey) &&
!e.shiftKey
) {
if (key === 'KeyV' && (e.metaKey || e.ctrlKey) && !e.shiftKey) {
// Trigger onPaste
return true
}

if (e.key === '+' && e.altKey) {
if ((key === 'NumpadAdd' || key === 'Equal') && e.altKey) {
block_default = true
let scale = this.ds.scale * 1.1
this.ds.changeScale(scale, [
Expand All @@ -1360,9 +1358,9 @@ export class ComfyApp {
this.graph.change()
}

if (e.key === '-' && e.altKey) {
if ((key === 'NumpadSubtract' || key === 'Minus') && e.altKey) {
block_default = true
let scale = (this.ds.scale * 1) / 1.1
let scale = this.ds.scale / 1.1
this.ds.changeScale(scale, [
this.ds.element.width / 2,
this.ds.element.height / 2
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/changeTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export class ChangeTracker {

async undoRedo(e) {
if (e.ctrlKey || e.metaKey) {
if (e.key === 'y') {
if (e.code === 'KeyY') {
this.updateState(this.redo, this.undo)
return true
} else if (e.key === 'z') {
} else if (e.code === 'KeyZ') {
this.updateState(this.undo, this.redo)
return true
}
Expand Down

0 comments on commit 23796d9

Please sign in to comment.