X Tutup
Skip to content

Fix modifier order in keycode string generation#108260

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
Silver1063:master
Sep 18, 2025
Merged

Fix modifier order in keycode string generation#108260
Repiteo merged 1 commit intogodotengine:masterfrom
Silver1063:master

Conversation

@Silver1063
Copy link
Contributor

Fix the order in which modifier keys are appended in as_text() and keycode_get_string() to ensure consistent and logical ordering (Ctrl, Alt, Shift, Meta). Refactored keycode_get_string() to use a vector for building the key string, improving readability and maintainability.

For example, creating a PopupMenu with an accelerator with ctrl, shift, n would result in the text displayed as "Shift + Ctrl + N" while adding the short cut with event N and modifiers ctrl and shift would result in text displayed as "Ctrl + Shift + N".

Both are now consistent.

@Silver1063 Silver1063 requested review from a team as code owners July 4, 2025 00:24
@Chaosus Chaosus added this to the 4.6 milestone Jul 4, 2025
Copy link
Contributor

@Sauermann Sauermann left a comment

Choose a reason for hiding this comment

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

It looks like the chosen order is consistent with reccomendations from Windows and Mac (https://superuser.com/questions/1238058/key-combination-order). So this PR is headed in the right direction.
I believe, that it is unlikely, that this change will affect users negatively. (that would require users to process the text output, which seems a silly idea)

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Code looks good to me.

I suggest adding unit tests for this in tests/core/input/test_input_event_key.h (look for existing instances of as_text in that file).

@Silver1063 Silver1063 requested a review from a team as a code owner July 6, 2025 04:24
@Silver1063
Copy link
Contributor Author

Silver1063 commented Jul 6, 2025

I've added the unit tests to check for the ordering of modifier keys.

@Silver1063
Copy link
Contributor Author

Silver1063 commented Jul 6, 2025

I've modified the tests so they pass on MacOS! Probably! (Fixed a small oopsie with on of the conditions too 🙈)

Fix the order in which modifier keys are appended in as_text() and keycode_get_string() to ensure consistent and logical ordering (Ctrl, Alt, Shift, Meta). Refactored keycode_get_string() to use a vector for building the key string, improving readability and maintainability.
@Silver1063
Copy link
Contributor Author

I noticed #108314 Somewhat related would replace that long macos condition.

@Repiteo Repiteo merged commit 1e84bc4 into godotengine:master Sep 18, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 18, 2025

Thanks! Congratulations on your first merged contribution! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

X Tutup