Skip to content

gpui: Fix incorrect handling of Function key modifier on macOS#38518

Merged
mikayla-maki merged 1 commit intozed-industries:mainfrom
unixzii:fix-fn-key
Nov 5, 2025
Merged

gpui: Fix incorrect handling of Function key modifier on macOS#38518
mikayla-maki merged 1 commit intozed-industries:mainfrom
unixzii:fix-fn-key

Conversation

@unixzii
Copy link
Contributor

@unixzii unixzii commented Sep 19, 2025

On macOS, the Function key is reserved for system use and should not be used in application code.

This commit updated keystroke matching and key event handling to ignore the Function key modifier while users are typing or pressing keybindings.

For some keyboards with compact layout (like my 65% keyboard), there is no separated backtick key. Esc and it shares the same physical key. To input backtick, users may press Fn-Esc. However, macOS will still deliver events with Fn key modifier to applications. Cocoa framework can handle this correctly, which typically ignore the Fn directly. GPUI should also follow the same rule, otherwise, the backtick key on those keyboards won't work.

Release Notes:

  • Fixed a bug where typing fn-` on macOS would not insert a `.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Sep 19, 2025
}
}

#[cfg(target_os = "macos")]
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want to remove the ability to respond to Fn keys at all, both Zed and Chrome use a function key binding to enable full screen on macOS.

@unixzii unixzii force-pushed the fix-fn-key branch 2 times, most recently from 582bfd9 to 8c5a61b Compare October 17, 2025 15:46
@unixzii
Copy link
Contributor Author

unixzii commented Oct 17, 2025

I updated this PR to only include some minimal changes. Now we only make sure ` can be input with Fn-` as other macOS apps do.

@unixzii unixzii requested a review from mikayla-maki October 18, 2025 06:50
On macOS, the Function key should not affect text inputs.

This commit updated the key event handling to ignore the Function key
modifier while users are typing.
Copy link
Member

@mikayla-maki mikayla-maki left a comment

Choose a reason for hiding this comment

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

Given that this PR brings our behavior more inline with other macOS apps, and that this PR doesn't affect the behavior of our own fn-fkeybinding or macOS' cmd-` keybinding, let's get it merged.

Thanks!

@mikayla-maki mikayla-maki enabled auto-merge (squash) November 5, 2025 23:17
@mikayla-maki mikayla-maki merged commit 2664596 into zed-industries:main Nov 5, 2025
26 checks passed
maxbrunsfeld pushed a commit that referenced this pull request Nov 6, 2025
On macOS, the Function key is reserved for system use and should not be
used in application code.

This commit updated keystroke matching and key event handling to ignore
the Function key modifier while users are typing or pressing
keybindings.

For some keyboards with compact layout (like my 65% keyboard), there is
no separated backtick key. Esc and it shares the same physical key. To
input backtick, users may press `Fn-Esc`. However, macOS will still
deliver events with Fn key modifier to applications. Cocoa framework can
handle this correctly, which typically ignore the Fn directly. GPUI
should also follow the same rule, otherwise, the backtick key on those
keyboards won't work.

Release Notes:

- Fixed a bug where typing fn-\` on macOS would not insert a `.
maxbrunsfeld pushed a commit that referenced this pull request Nov 6, 2025
On macOS, the Function key is reserved for system use and should not be
used in application code.

This commit updated keystroke matching and key event handling to ignore
the Function key modifier while users are typing or pressing
keybindings.

For some keyboards with compact layout (like my 65% keyboard), there is
no separated backtick key. Esc and it shares the same physical key. To
input backtick, users may press `Fn-Esc`. However, macOS will still
deliver events with Fn key modifier to applications. Cocoa framework can
handle this correctly, which typically ignore the Fn directly. GPUI
should also follow the same rule, otherwise, the backtick key on those
keyboards won't work.

Release Notes:

- Fixed a bug where typing fn-\` on macOS would not insert a `.
tomatitito pushed a commit to tomatitito/zed that referenced this pull request Nov 7, 2025
…ndustries#38518)

On macOS, the Function key is reserved for system use and should not be
used in application code.

This commit updated keystroke matching and key event handling to ignore
the Function key modifier while users are typing or pressing
keybindings.

For some keyboards with compact layout (like my 65% keyboard), there is
no separated backtick key. Esc and it shares the same physical key. To
input backtick, users may press `Fn-Esc`. However, macOS will still
deliver events with Fn key modifier to applications. Cocoa framework can
handle this correctly, which typically ignore the Fn directly. GPUI
should also follow the same rule, otherwise, the backtick key on those
keyboards won't work.

Release Notes:

- Fixed a bug where typing fn-\` on macOS would not insert a `.
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
…ndustries#38518)

On macOS, the Function key is reserved for system use and should not be
used in application code.

This commit updated keystroke matching and key event handling to ignore
the Function key modifier while users are typing or pressing
keybindings.

For some keyboards with compact layout (like my 65% keyboard), there is
no separated backtick key. Esc and it shares the same physical key. To
input backtick, users may press `Fn-Esc`. However, macOS will still
deliver events with Fn key modifier to applications. Cocoa framework can
handle this correctly, which typically ignore the Fn directly. GPUI
should also follow the same rule, otherwise, the backtick key on those
keyboards won't work.

Release Notes:

- Fixed a bug where typing fn-\` on macOS would not insert a `.
@unixzii unixzii deleted the fix-fn-key branch December 24, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants