Fix #146413: Truncate socket names only if space is present after prefix

In 95259228d9 an optimization was made to
simplify geometry nodes socket names on panels when they contain the
exact group title as prefix, but this leads to issue where `Opening` can
be truncated as `ing` which is not desired. Now will check if a space
character is present after the prefix, then do the truncation.

Note that this implementation still doesn't truncate `CamelCase` or any
CJK name strings because they don't use the space character as
separator.

Pull Request: https://projects.blender.org/blender/blender/pulls/146973
This commit is contained in:
YimingWu
2025-09-29 17:37:17 +02:00
committed by YimingWu
parent 02bdc709c2
commit 5cde024fc9

View File

@@ -508,13 +508,10 @@ static void draw_property_for_socket(DrawGroupInputsContext &ctx,
* the prefix so it appears less verbose. */
if (parent_name.has_value()) {
const StringRef prefix_to_remove = *parent_name;
int pos = name.find(prefix_to_remove);
if (pos == 0 && name != prefix_to_remove) {
/* Needs to trim remaining space characters if any. Use the `trim()` from `StringRefNull`
* because std::string doesn't have a built-in `trim()` yet. If the property name is the
* same as parent panel's name then keep the name, otherwise the name would be an empty
* string which messes up the UI. */
name = StringRefNull(name.substr(prefix_to_remove.size())).trim();
const int prefix_size = prefix_to_remove.size();
const int pos = name.find(prefix_to_remove);
if (pos == 0 && name.size() > prefix_size && name[prefix_size] == ' ') {
name = name.substr(prefix_size + 1);
}
}