Merge pull request #5561 from tonhuisman/feature/Sysvar-variables-num-sorted

[SysVars] List variables numerically sorted
This commit is contained in:
TD-er
2026-06-07 21:43:17 +02:00
committed by GitHub
2 changed files with 41 additions and 2 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ Optional, but highly recommended:
* C/C++ DevTools (by Microsoft)
* Bookmarks (by Alessandro Fragnani)
* GitLens - Git supercharged (by Gitkraken)
* Todo Tree (by Gruntfuggly)
* TODO Highlight (by Wayou Liu)
* All Autocomplete (by Atishay Jain)
* Excel Viewer (by GrapeCity)
* Esbonio - An extension for editing sphinx projects (by Swyddfa)
+40 -1
View File
@@ -52,6 +52,19 @@ void handle_sysvars() {
html_table_header(F("URL encoded"), F("RTDReference/SystemVariable.html"), 0);
addTableSeparator(F("Custom Variables"), 3, 3);
# if !defined(LIMIT_BUILD_SIZE) || FEATURE_STRING_VARIABLES
auto numAlphaSort = [](const String& a, const String& b) {
const int32_t ai = a.toInt();
const int32_t bi = b.toInt();
if (!ai && !bi) { return a < b; } // a..z
if (!ai) { return false; } // Alphanum after num
return ai < bi; // Numerical order
};
std::vector<String> customStringSort;
# endif // if !defined(LIMIT_BUILD_SIZE) || FEATURE_STRING_VARIABLES
if (customFloatVar.empty()) {
html_TR_TD();
@@ -59,14 +72,33 @@ void handle_sysvars() {
html_TD();
html_TD();
} else {
# if !defined(LIMIT_BUILD_SIZE) || FEATURE_STRING_VARIABLES
for (auto it = customFloatVar.begin(); it != customFloatVar.end(); ++it) {
customStringSort.push_back(it->first);
}
std::sort(customStringSort.begin(), customStringSort.end(), numAlphaSort);
for (auto& it : customStringSort) {
NumericalType detectedType;
bool isv_ = true;
if (getNumerical(it, NumericalType::HexadecimalUInt, detectedType).length() > 0) {
isv_ = detectedType != NumericalType::Integer;
}
addSysVar_html(strformat(F("%%%s%s%%"), FsP(isv_ ? F("v_") : F("v")), it.c_str()), false);
}
# else // if !defined(LIMIT_BUILD_SIZE) || FEATURE_STRING_VARIABLES
for (auto it = customFloatVar.begin(); it != customFloatVar.end(); ++it) {
NumericalType detectedType;
bool isv_ = true;
if (getNumerical(it->first, NumericalType::HexadecimalUInt, detectedType).length() > 0) {
isv_ = detectedType != NumericalType::Integer;
}
addSysVar_html(strformat(F("%%%s%s%%"), FsP(isv_ ? F("v_") : F("v")), it->first.c_str()), false);
}
# endif // if !defined(LIMIT_BUILD_SIZE) || FEATURE_STRING_VARIABLES
}
# if FEATURE_STRING_VARIABLES
@@ -78,8 +110,15 @@ void handle_sysvars() {
html_TD();
html_TD();
} else {
customStringSort.clear();
for (auto it = customStringVar.begin(); it != customStringVar.end(); ++it) {
addSysVar_html(strformat(F("[str#%s]"), it->first.c_str()), false);
customStringSort.push_back(it->first);
}
std::sort(customStringSort.begin(), customStringSort.end(), numAlphaSort);
for (auto& it : customStringSort) {
addSysVar_html(strformat(F("[str#%s]"), it.c_str()), false);
}
}
# endif // if FEATURE_STRING_VARIABLES