Fix modifier order in keycode string generation

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.
This commit is contained in:
Silver1063 2025-07-03 17:16:40 -07:00
parent 53be3b78d1
commit 00f5b230be
3 changed files with 46 additions and 30 deletions

View file

@ -125,6 +125,17 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
none_key.set_physical_keycode(Key::ENTER);
CHECK(none_key.as_text() == "Ctrl+Enter (Physical)");
// Key is None WITH a physical key AND multiple modifiers, checks for correct ordering.
none_key.set_alt_pressed(true);
none_key.set_shift_pressed(true);
#ifdef MACOS_ENABLED
CHECK(none_key.as_text() != "Ctrl+Shift+Option+Enter (Physical)");
CHECK(none_key.as_text() == "Ctrl+Option+Shift+Enter (Physical)");
#else
CHECK(none_key.as_text() != "Ctrl+Shift+Alt+Enter (Physical)");
CHECK(none_key.as_text() == "Ctrl+Alt+Shift+Enter (Physical)");
#endif
InputEventKey none_key2;
// Key is None without modifiers with a physical key.
@ -145,6 +156,17 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
CHECK(key.as_text() != "Space");
CHECK(key.as_text() == "Ctrl+Space");
// Key has keycode and multiple modifiers, checks for correct ordering.
key.set_alt_pressed(true);
key.set_shift_pressed(true);
#ifdef MACOS_ENABLED
CHECK(key.as_text() != "Ctrl+Shift+Option+Space");
CHECK(key.as_text() == "Ctrl+Option+Shift+Space");
#else
CHECK(key.as_text() != "Ctrl+Shift+Alt+Space");
CHECK(key.as_text() == "Ctrl+Alt+Shift+Space");
#endif
// Since the keycode is set to Key::NONE upon initialization of the
// InputEventKey and you can only update it with another Key, the keycode
// cannot be empty, so the kc.is_empty() case cannot be tested.