You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
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:
@@ -360,51 +360,45 @@ bool keycode_has_unicode(Key p_keycode) {
|
||||
}
|
||||
|
||||
String keycode_get_string(Key p_code) {
|
||||
String codestr;
|
||||
if ((p_code & KeyModifierMask::SHIFT) != Key::NONE) {
|
||||
codestr += find_keycode_name(Key::SHIFT);
|
||||
codestr += "+";
|
||||
}
|
||||
if ((p_code & KeyModifierMask::ALT) != Key::NONE) {
|
||||
codestr += find_keycode_name(Key::ALT);
|
||||
codestr += "+";
|
||||
}
|
||||
if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE) {
|
||||
if (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios")) {
|
||||
codestr += find_keycode_name(Key::META);
|
||||
} else {
|
||||
codestr += find_keycode_name(Key::CTRL);
|
||||
}
|
||||
codestr += "+";
|
||||
Vector<String> keycode_string;
|
||||
if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && !(OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios"))) {
|
||||
keycode_string.push_back(find_keycode_name(Key::CTRL));
|
||||
}
|
||||
if ((p_code & KeyModifierMask::CTRL) != Key::NONE) {
|
||||
codestr += find_keycode_name(Key::CTRL);
|
||||
codestr += "+";
|
||||
keycode_string.push_back(find_keycode_name(Key::CTRL));
|
||||
}
|
||||
if ((p_code & KeyModifierMask::ALT) != Key::NONE) {
|
||||
keycode_string.push_back(find_keycode_name(Key::ALT));
|
||||
}
|
||||
if ((p_code & KeyModifierMask::SHIFT) != Key::NONE) {
|
||||
keycode_string.push_back(find_keycode_name(Key::SHIFT));
|
||||
}
|
||||
if ((p_code & KeyModifierMask::CMD_OR_CTRL) != Key::NONE && (OS::get_singleton()->has_feature("macos") || OS::get_singleton()->has_feature("web_macos") || OS::get_singleton()->has_feature("web_ios"))) {
|
||||
keycode_string.push_back(find_keycode_name(Key::META));
|
||||
}
|
||||
if ((p_code & KeyModifierMask::META) != Key::NONE) {
|
||||
codestr += find_keycode_name(Key::META);
|
||||
codestr += "+";
|
||||
keycode_string.push_back(find_keycode_name(Key::META));
|
||||
}
|
||||
|
||||
p_code &= KeyModifierMask::CODE_MASK;
|
||||
if ((char32_t)p_code == 0) {
|
||||
// The key was just a modifier without any code.
|
||||
return codestr;
|
||||
return String("+").join(keycode_string);
|
||||
}
|
||||
|
||||
// The key is a named keycode.
|
||||
const _KeyCodeText *kct = &_keycodes[0];
|
||||
|
||||
while (kct->text) {
|
||||
if (kct->code == p_code) {
|
||||
codestr += kct->text;
|
||||
return codestr;
|
||||
keycode_string.push_back(kct->text);
|
||||
return String("+").join(keycode_string);
|
||||
}
|
||||
kct++;
|
||||
}
|
||||
|
||||
codestr += String::chr((char32_t)p_code);
|
||||
|
||||
return codestr;
|
||||
// The key is a single character.
|
||||
keycode_string.push_back(String::chr((char32_t)p_code));
|
||||
return String("+").join(keycode_string);
|
||||
}
|
||||
|
||||
Key find_keycode(const String &p_codestr) {
|
||||
|
||||
Reference in New Issue
Block a user