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

(GPUI on Windows) Zed assumes keycodes originate from US Keyboards, causing mismatches in characters #12811

Open
1 task done
agamcsama opened this issue Jun 8, 2024 · 3 comments
Labels
bug [core label] gpui GPUI rendering framework support internationalization Feedback for human language support, translations, etc keybinds Keyboard shortcuts, mapping, binding, keymaps, etc

Comments

@agamcsama
Copy link
Contributor

agamcsama commented Jun 8, 2024

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

I am using a keyboard with a British ISO layout. I am having issues with the following characters:
' ~ `
When I am typing them into the buffer, they work as usual. However when trying to use keymaps with them, they do the actions of other binds:
ctrl-' -> ctrl-~
ctrl-~ -> ctrl-'
ctrl-` -> Nothing

When testing, it seems that https://www.keyboardtester.com/tester.html recieves my inputs just like Zed does when handling keymaps, pressing ' returns ~, ~ returns ' and ` doesn't even show up.

Environment

Zed: v0.140.0 (Zed Dev e829a8c)
OS: Windows 10.0.22631
Memory: 31.8 GiB
Architecture: x86_64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

@agamcsama agamcsama added admin read bug [core label] labels Jun 8, 2024
@agamcsama
Copy link
Contributor Author

agamcsama commented Jun 8, 2024

After some digging, I have found a similar issue online.

The important part is that keycodes can refer to different characters on different platforms. I have found the line of code that assigns the keycode of 192 to `, however this is only true for US ANSI Keyboards, not others such as British ISO keyboards.

Here is a line of code where GPUI interprets the 192 keycode as a ` , which is incorrect behaviour. It should check, and return different characters for different keyboards, where the same keycodes can refer to different characters.

192 => Some("`".to_string()), // VK_OEM_3

@agamcsama agamcsama changed the title Certain keybinds don't work with non-ansi keyboards.` (Windows) Zed assumes keycodes originate from US Keyboards, causing mismatches in characters Jun 8, 2024
@agamcsama agamcsama changed the title (Windows) Zed assumes keycodes originate from US Keyboards, causing mismatches in characters (GPUI on Windows) Zed assumes keycodes originate from US Keyboards, causing mismatches in characters Jun 8, 2024
@agamcsama
Copy link
Contributor Author

agamcsama commented Jun 8, 2024

I think the intended way to do this on windows would be to use the MapVirtualKeyW function (docs).

Though I am not experienced with the win32 api, I've found a crude way to replace the match statement that seems to fix the issue:

char::from_u32(MapVirtualKeyW(code as u32, MAPVK_VK_TO_CHAR)).map(String::from)

I will start working on a pull request.

@Moshyfawn Moshyfawn added internationalization Feedback for human language support, translations, etc keybinds Keyboard shortcuts, mapping, binding, keymaps, etc and removed triage labels Jun 10, 2024
@JosephTLyons JosephTLyons added gpui GPUI rendering framework support and removed admin read labels Jun 11, 2024
mikayla-maki added a commit that referenced this issue Jun 20, 2024
Release Notes:

- Fixed Zed/GPUI misinterpreting keycodes on non-US keyboards
([#12811](#12811)).

---------

Co-authored-by: Marshall Bowers <[email protected]>
Co-authored-by: Mikayla Maki <[email protected]>
@notpeter
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [core label] gpui GPUI rendering framework support internationalization Feedback for human language support, translations, etc keybinds Keyboard shortcuts, mapping, binding, keymaps, etc
Projects
None yet
Development

No branches or pull requests

4 participants