Comfy-Org / ComfyUI_frontend

Official front-end implementation of ComfyUI
https://www.comfy.org/
GNU General Public License v3.0
627 stars 115 forks source link

[Feature Request]: temporarily disable hotkeys or context based hotkeys #1595

Open trsommer opened 5 days ago

trsommer commented 5 days ago

Is there an existing issue for this?

What would your feature do ?

A developer api to temporarily disable hotkeys. When a user opens the Mask Editor and presses Ctrl+Z, the undo operation should affect the Mask Editor rather than triggering ComfyUI's global undo functionality.

A better alternative would be a developer API to create hotkeys that only affect a certain context. Context could be enabled and disabled.

Proposed workflow

// Usage example 1

app.extensionManager.disableKeybindings('commandId1'); app.extensionManager.enableKeybindings(['commandId1', 'commandId2']);

//Usage example 2

//create context and keybinding via app.registerExtension

app.extensionManager.enableHotkeyContext('contextId') app.extensionManager.disableHotkeyContext('contextId')

Additional information

No response

huchenlei commented 4 days ago

https://github.com/Comfy-Org/ComfyUI_frontend/pull/1230 tries to manage redo/undo in the new keyboard shortcut system, however there are some tricky parts.

Is it possible for you to capture the event you care like Ctrl-Z on the mask editor elements and stop its propagation immediately now?

trsommer commented 3 days ago

We definitely need #1230 as it unifies the keyboard listener. However, it doesn't resolve the issue where all canvas keybindings can still be triggered from the mask editor (e.g. Ctrl + O). The new keyboard shortcut system managing undo and redo actions doesn't address that problem (at least I don't see how it does). They behave like all other keybindings now.

In my opinion, in the short term, the best solution is to disable certain hotkeys from triggering using a command or through app.registerExtension. In the long term, the ideal solution would be to define different hotkey contexts (e.g., one for the canvas, another for the mask editor, and possibly others). Each context would handle keybindings separately, ensuring that hotkeys do not trigger in the wrong context and allowing for double definitions of hotkeys. Users will likely want to change the mask editor keybindings as well, so there needs to be a way to do that in the settings.