mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 12:52:10 -03:00
Fix keyboard shortcuts capturing events when node is unfocused
Prevent LayerForge from intercepting Ctrl+C, Ctrl+V, and other keyboard shortcuts when the canvas is not focused. This was causing unwanted popups and interfering with other nodes in ComfyUI. Changes: - Remove document.body focus check from handlePasteEvent - Add focus validation to handleKeyDown before processing shortcuts - Modifier keys (Ctrl, Shift, Alt, Meta) are still tracked globally - All other shortcuts only trigger when canvas is focused Fixes issue where paste events were captured globally regardless of focus.
This commit is contained in:
@@ -519,14 +519,24 @@ export class CanvasInteractions {
|
||||
return targetHeight / oldHeight;
|
||||
}
|
||||
handleKeyDown(e) {
|
||||
// Always track modifier keys regardless of focus
|
||||
if (e.key === 'Control')
|
||||
this.interaction.isCtrlPressed = true;
|
||||
if (e.key === 'Meta')
|
||||
this.interaction.isMetaPressed = true;
|
||||
if (e.key === 'Shift')
|
||||
this.interaction.isShiftPressed = true;
|
||||
if (e.key === 'Alt') {
|
||||
if (e.key === 'Alt')
|
||||
this.interaction.isAltPressed = true;
|
||||
// Check if canvas is focused before handling any shortcuts
|
||||
const shouldHandle = this.canvas.isMouseOver ||
|
||||
this.canvas.canvas.contains(document.activeElement) ||
|
||||
document.activeElement === this.canvas.canvas;
|
||||
if (!shouldHandle) {
|
||||
return;
|
||||
}
|
||||
// Canvas-specific key handlers (only when focused)
|
||||
if (e.key === 'Alt') {
|
||||
e.preventDefault();
|
||||
}
|
||||
if (e.key.toLowerCase() === 's') {
|
||||
@@ -1157,8 +1167,7 @@ export class CanvasInteractions {
|
||||
async handlePasteEvent(e) {
|
||||
const shouldHandle = this.canvas.isMouseOver ||
|
||||
this.canvas.canvas.contains(document.activeElement) ||
|
||||
document.activeElement === this.canvas.canvas ||
|
||||
document.activeElement === document.body;
|
||||
document.activeElement === this.canvas.canvas;
|
||||
if (!shouldHandle) {
|
||||
log.debug("Paste event ignored - not focused on canvas");
|
||||
return;
|
||||
|
||||
@@ -646,11 +646,23 @@ export class CanvasInteractions {
|
||||
}
|
||||
|
||||
handleKeyDown(e: KeyboardEvent): void {
|
||||
// Always track modifier keys regardless of focus
|
||||
if (e.key === 'Control') this.interaction.isCtrlPressed = true;
|
||||
if (e.key === 'Meta') this.interaction.isMetaPressed = true;
|
||||
if (e.key === 'Shift') this.interaction.isShiftPressed = true;
|
||||
if (e.key === 'Alt') this.interaction.isAltPressed = true;
|
||||
|
||||
// Check if canvas is focused before handling any shortcuts
|
||||
const shouldHandle = this.canvas.isMouseOver ||
|
||||
this.canvas.canvas.contains(document.activeElement) ||
|
||||
document.activeElement === this.canvas.canvas;
|
||||
|
||||
if (!shouldHandle) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Canvas-specific key handlers (only when focused)
|
||||
if (e.key === 'Alt') {
|
||||
this.interaction.isAltPressed = true;
|
||||
e.preventDefault();
|
||||
}
|
||||
if (e.key.toLowerCase() === 's') {
|
||||
@@ -664,7 +676,7 @@ export class CanvasInteractions {
|
||||
this.canvas.shapeTool.activate();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Globalne skróty (Undo/Redo/Copy/Paste)
|
||||
const mods = this.getModifierState(e);
|
||||
if (mods.ctrl || mods.meta) {
|
||||
@@ -1345,9 +1357,8 @@ export class CanvasInteractions {
|
||||
|
||||
const shouldHandle = this.canvas.isMouseOver ||
|
||||
this.canvas.canvas.contains(document.activeElement) ||
|
||||
document.activeElement === this.canvas.canvas ||
|
||||
document.activeElement === document.body;
|
||||
|
||||
document.activeElement === this.canvas.canvas;
|
||||
|
||||
if (!shouldHandle) {
|
||||
log.debug("Paste event ignored - not focused on canvas");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user