Skip to content

macOS: use KeyboardShortcut rather than homegrown KeyEquivalent #7139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025

Conversation

mitchellh
Copy link
Contributor

@mitchellh mitchellh commented Apr 19, 2025

This replaces the use of our custom Ghostty.KeyEquivalent with the SwiftUI KeyboardShortcut type. This is a more standard way to represent keyboard shortcuts and lets us more tightly integrate with SwiftUI/AppKit when necessary over our custom type.

This PR should have no user impact. This is just some cleanup for future work.

Note that not all Ghostty triggers can be represented as KeyboardShortcut values because macOS itself does not support binding keys such as function keys (e.g. F1-F12) to KeyboardShortcuts.

This isn't an issue since all input also passes through a lower level libghostty API which can handle all key events, we just can't show these keyboard shortcuts on things like the menu bar. This was already true before this commit.

This replaces the use of our custom `Ghostty.KeyEquivalent` with
the SwiftUI `KeyboardShortcut` type. This is a more standard way to
represent keyboard shortcuts and lets us more tightly integrate with
SwiftUI/AppKit when necessary over our custom type.

Note that not all Ghostty triggers can be represented as
KeyboardShortcut values because macOS itself does not support
binding keys such as function keys (e.g. F1-F12) to KeyboardShortcuts.

This isn't an issue since all input also passes through a lower level
libghostty API which can handle all key events, we just can't show these
keyboard shortcuts on things like the menu bar. This was already true
before this commit.
Comment on lines +20 to +21
let keyString: String
switch key {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use the let keyString = switch key { ... } syntax here.

@mitchellh mitchellh marked this pull request as ready for review April 21, 2025 14:26
@mitchellh mitchellh requested a review from a team as a code owner April 21, 2025 14:26
@mitchellh
Copy link
Contributor Author

Let's send this and see if it causes any issues.

@mitchellh mitchellh merged commit 643c882 into main Apr 21, 2025
69 checks passed
@mitchellh mitchellh deleted the push-ypspmkloxvzo branch April 21, 2025 14:26
@github-actions github-actions bot added this to the 1.2.0 milestone Apr 21, 2025
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.

2 participants