fix: gate anchor shortcuts to DAG context (#54) - #60
Merged
Merged
Conversation
Anchor functions are only meaningful in the Node Graph, but their keyboard shortcuts fired application-wide — so Ctrl+C/X/V intercepted text editing in the Script Editor, and single-key bindings like A collided with other panels. Bind every shortcut-bearing anchor command to Nuke's DAG shortcut context (shortcutContext=2) so the keys only fire when the Node Graph has focus: - Add a named DAG_SHORTCUT_CONTEXT constant in constants.py. - _add_gated_command now defaults any command that binds a shortcut to the DAG context (override still possible via shortcut_context). - Apply the context to the top-level Copy/Cut/Paste/Input On/Off overrides and the Paste (old) fallback, which use addCommand directly. - Switch the existing Leader Key binding to the named constant. Adds tests/test_menu_shortcut_context.py, which imports menu.py against a recording nuke stub and asserts every shortcut is DAG-gated while commands without a shortcut carry no spurious context. Documents the gating in README.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR scopes all anchor-related keyboard shortcuts to Nuke’s DAG (Node Graph) shortcut context to prevent anchor shortcuts (notably Ctrl+C/X/V and single-key bindings like A) from firing in non-DAG panels such as the Script Editor or Viewer (closes #54).
Changes:
- Introduces a named
DAG_SHORTCUT_CONTEXTconstant and applies it across shortcut registrations. - Updates
menu.pyso shortcut-bearing commands default to DAG context gating, including top-level Edit overrides and the “Paste (old)” fallback. - Adds a regression test to assert that all shortcut-bearing commands are DAG-gated and that non-shortcut commands don’t carry a context; README updated to document the behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
constants.py |
Adds DAG_SHORTCUT_CONTEXT = 2 with documentation to centralize DAG shortcut scoping. |
menu.py |
Applies DAG shortcut gating to all anchor shortcuts and makes _add_gated_command default shortcut-bearing commands to DAG context. |
tests/test_menu_shortcut_context.py |
New test that records addCommand calls and asserts correct shortcutContext behavior. |
README.md |
Documents that anchor shortcuts only fire when the Node Graph has focus. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #54.
Problem
Anchor keyboard shortcuts were registered application-wide, so they fired regardless of which panel had focus. The most disruptive cases:
Ctrl+C/Ctrl+X/Ctrl+Vare wrapped to copy/cut/paste hidden-input anchors, so they intercepted ordinary text editing in the Script Editor.Acollided with shortcuts in the Viewer and other panels.Anchor functions are only meaningful in the Node Graph, so these shortcuts have no business firing elsewhere.
Fix
Bind every shortcut-bearing anchor command to Nuke's DAG shortcut context (
shortcutContext=2) so the keys only fire when the Node Graph has focus.DAG_SHORTCUT_CONTEXTconstant inconstants.py._add_gated_commandnow defaults any command that binds a shortcut to the DAG context (an explicitshortcut_contextstill overrides).Copy/Cut/Paste/Input On/Offoverrides and thePaste (old)fallback, which calladdCommanddirectly.Leader Keybinding from the literal2to the named constant.The leader key already used
shortcutContext=2; this extends the same gating to the rest of the anchor shortcuts for consistency.Tests
Adds
tests/test_menu_shortcut_context.py, which importsmenu.pyagainst a recordingnukestub and asserts:^C,^X,^V,A,+A,alt+A/J/L/Z,+M/N/B,^M,+^D) are all present and gated,Full suite: 482 passed. README updated to document the DAG-context scoping.