Skip to content

Fix keyboard handling when Visage is hosted inside a plugin on macOS#81

Open
danielraffel wants to merge 1 commit intoVitalAudio:mainfrom
danielraffel:fix/macos-plugin-keyboard-handling
Open

Fix keyboard handling when Visage is hosted inside a plugin on macOS#81
danielraffel wants to merge 1 commit intoVitalAudio:mainfrom
danielraffel:fix/macos-plugin-keyboard-handling

Conversation

@danielraffel
Copy link
Copy Markdown
Contributor

Two related issues when a Visage view is embedded inside a host application (e.g. an audio plugin running in a DAW):

1. Text editing shortcuts don't work (Cmd+C/V/X/A/Z)

On macOS, the host's menu system handles performKeyEquivalent: before keyDown: is called. The host's Edit menu intercepts Cmd+C, Cmd+V, etc., so they never reach Visage text editors.

This adds a performKeyEquivalent: override that checks hasActiveTextEntry(). When a text editor has focus, the shortcut is routed through handleKeyDown so copy/paste/select-all/undo work. When no text editor is active, the event falls through to the host so its menu shortcuts keep working normally.

2. Unhandled command-key events are silently swallowed

[super keyDown:] on macOS does not propagate events up the responder chain — it consumes them. So shortcuts like Cmd+Q never reach the application-level handler.

This forwards unhandled command-key events to [self nextResponder] instead of [super keyDown:] so they propagate up to the app. Non-command keys still go through [super keyDown:] as before.


Discovered while working on a macOS JUCE audio plugin that uses Visage for its UI. This PR was put together with the help of Claude. Completely understand if you'd prefer to close this — just wanted to share the fixes since we've been patching around them on our end whenever we update Visage.

Two related issues when a Visage view is embedded inside a host
application (e.g. an audio plugin running in a DAW):

1. Command-key shortcuts (Cmd+C, Cmd+V, Cmd+A, Cmd+X, Cmd+Z) never
   reach Visage text editors. On macOS, the host's menu system handles
   performKeyEquivalent: before keyDown: is called, so the host's
   Edit menu intercepts these shortcuts.

   Add a performKeyEquivalent: override that checks
   hasActiveTextEntry(). When a text editor has focus, route the
   shortcut through handleKeyDown so copy/paste/select-all/undo work.
   When no text editor is active, fall through to the host so its
   menu shortcuts keep working normally.

2. Unhandled command-key events (like Cmd+Q) get silently swallowed.
   [super keyDown:] on macOS does not propagate events up the
   responder chain — it just consumes them. So Cmd+Q never reaches
   the application-level handler.

   Forward unhandled command-key events to [self nextResponder]
   instead of [super keyDown:] so they propagate up to the app.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant