Avoid nested parentheses in physical/Unicode InputEventKey text conversion

This was visible in tooltips displayed in shortcuts, including in the editor itself.

For example, "Forward (W (Physical))" is now displayed as "Forward (W - Physical)".
This commit is contained in:
Hugo Locurcio 2025-12-02 01:18:53 +01:00
parent f5918a9d35
commit e483d2e2d1
No known key found for this signature in database
GPG key ID: 46ACE49F61685096
3 changed files with 18 additions and 18 deletions

View file

@ -110,30 +110,30 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
// These next three tests test the functionality of getting a key that is set to None
// as text. These cases are a bit weird, since None has no textual representation
// (find_keycode_name(Key::NONE) results in a nullptr). Thus, these tests look weird
// with only (Physical) or a lonely modifier with (Physical) but (as far as I
// with only "- Physical" or a lonely modifier with "- Physical" but (as far as I
// understand the code, that is intended behavior.
// Key is None without a physical key.
none_key.set_keycode(Key::NONE);
CHECK(none_key.as_text() == "(Unset)");
CHECK(none_key.as_text() == "(unset)");
// Key is none and has modifiers.
none_key.set_ctrl_pressed(true);
CHECK(none_key.as_text() == "Ctrl+(Unset)");
CHECK(none_key.as_text() == "Ctrl+(unset)");
// Key is None WITH a physical key AND modifiers.
none_key.set_physical_keycode(Key::ENTER);
CHECK(none_key.as_text() == "Ctrl+Enter (Physical)");
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)");
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)");
CHECK(none_key.as_text() != "Ctrl+Shift+Alt+Enter - Physical");
CHECK(none_key.as_text() == "Ctrl+Alt+Shift+Enter - Physical");
#endif
InputEventKey none_key2;
@ -142,7 +142,7 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
none_key2.set_keycode(Key::NONE);
none_key2.set_physical_keycode(Key::ENTER);
CHECK(none_key2.as_text() == "Enter (Physical)");
CHECK(none_key2.as_text() == "Enter - Physical");
InputEventKey key;
@ -175,7 +175,7 @@ TEST_CASE("[InputEventKey] Key correctly converts itself to text") {
TEST_CASE("[InputEventKey] Key correctly converts its state to a string representation") {
InputEventKey none_key;
CHECK(none_key.to_string() == "InputEventKey: keycode=(Unset), mods=none, physical=false, location=unspecified, pressed=false, echo=false");
CHECK(none_key.to_string() == "InputEventKey: keycode=(unset), mods=none, physical=false, location=unspecified, pressed=false, echo=false");
// Set physical key to Escape.
none_key.set_physical_keycode(Key::ESCAPE);
CHECK(none_key.to_string() == "InputEventKey: keycode=4194305 (Escape), mods=none, physical=true, location=unspecified, pressed=false, echo=false");