Skip to content
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

input: legacy encoding never encodes text for command mods on macOS #6057

Merged
merged 1 commit into from
Mar 2, 2025

Conversation

mitchellh
Copy link
Contributor

@mitchellh mitchellh commented Mar 2, 2025

Fixes #5929
Replaces #5984

On macOS, native applications typically never encode any text for key events that use the command key. This is because the command key is used for key equivalents and "commands" and should not be used for text input.

This can be verified with apps like TextEdit but also terminals like Terminal.app officially but also iTerm2 unofficially. Anything such as Cmd+b or Cmd+Shift+b will not produce any text input.

Cross-platform terminals generally don't follow this, for example Kitty performs CSI-u encoding and Alacritty and WezTerm encode the text as-is (i.e. Cmd+b will produce b).

On Linux, the super key (command-equivalent) does produce text input. For example, Super+b will produce b in Gnome Console, Foot, and all the cross-platform terminals mentioned above.

In the interest of matching the behavior of native macOS applications, we should not encode text for command key events on macOS. We continue to encode text for the super key on non-macOS platforms. This matches the behaviors appropriately on each platform.

Fixes #5929
Replaces #5984

On macOS, native applications typically never encode any text for
key events that use the command key. This is because the command key
is used for key equivalents and "commands" and should not be used
for text input.

This can be verified with apps like TextEdit but also terminals like
Terminal.app officially but also iTerm2 unofficially. Anything such as
`Cmd+b` or `Cmd+Shift+b` will not produce any text input.

Cross-platform terminals generally don't follow this, for example Kitty
performs CSI-u encoding and Alacritty and WezTerm encode the text as-is
(i.e. `Cmd+b` will produce `b`).

On Linux, the super key (command-equivalent) does produce text input.
For example, `Super+b` will produce `b` in Gnome Console, Foot, and
all the cross-platform terminals mentioned above.

In the interest of matching the behavior of native macOS applications,
we should not encode text for command key events on macOS. We continue
to encode text for the super key on non-macOS platforms.
// with legacy encoding.
if ((comptime builtin.os.tag == .macos) and all_mods.super) {
return "";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will note that it is possible that this check is too late. We may want to omit ctrl sequence and other encodings as well when the super key is pressed on macOS. But the tests only cover this and this was the least-impacting change I could do with a very specific real world bug to verify it resolves.

I'd be open to a broader change with a bit more research.

@rockorager
Copy link
Member

Just so I understand... kkp encoding will still encode the associated text field when super + "b" is pressed? I am thinking we shouldn't do that and instead report it as no produced text...what do you think?

@mitchellh
Copy link
Contributor Author

mitchellh commented Mar 2, 2025

Just so I understand... kkp encoding will still encode the associated text field when super + "b" is pressed? I am thinking we shouldn't do that and instead report it as no produced text...what do you think?

I can confirm it does not produce text, and the behavior matches Kitty. EDIT: more specifically, we produce super + b but no associated text.

@rockorager rockorager merged commit ee8ae19 into main Mar 2, 2025
58 checks passed
@rockorager rockorager deleted the push-zmsrlvnzwxpo branch March 2, 2025 22:21
@github-actions github-actions bot added this to the 1.2.0 milestone Mar 2, 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.

macOS: Cmd+H should not send "h" if its the last visible window
2 participants