Browse Source

fix regression of #6235

Laserlicht 1 month ago
parent
commit
35b294611c
1 changed files with 17 additions and 4 deletions
  1. 17 4
      client/windows/GUIClasses.cpp

+ 17 - 4
client/windows/GUIClasses.cpp

@@ -1671,11 +1671,24 @@ void CObjectListWindow::trimTextIfTooWide(std::string & text) const
 	int maxWidth = pos.w - 60;	// 60 px for scrollbar and borders
 	auto posBrace = text.find('(');
 	auto posClosing = text.find(')');
-	std::string objCount = text.substr(posBrace, posClosing - posBrace) + ')';
-	if(text[0] == '{')
-		objCount = '}' + objCount;
+
+	std::string objCount;
+	if (posBrace != std::string::npos && posClosing != std::string::npos && posClosing > posBrace)
+	{
+		objCount = text.substr(posBrace, posClosing - posBrace) + ')';
+		if(text.size() > 0 && text[0] == '{')
+			objCount = '}' + objCount;
+	}
+	else
+	{
+		// fallback: if text starts with '{', keep a trailing '}' token, otherwise empty
+		if(text.size() > 0 && text[0] == '{')
+			objCount = "}";
+		else
+			objCount.clear();
+	}
 	const auto & font = ENGINE->renderHandler().loadFont(FONT_SMALL);
-	std::string suffix = "... " + objCount;
+	std::string suffix = objCount.empty() ? "..." : std::string("... ") + objCount;
 
 	if(font->getStringWidth(text) >= maxWidth)
 	{