1
0
Fork 0

Merge pull request #3681 from dabeibao/development

Goto dialog: add completion for labels
This commit is contained in:
Duncan Ogilvie 2025-08-17 17:50:53 +02:00 committed by GitHub
commit cca598427f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 1 deletions

View File

@ -32,6 +32,7 @@
#include "database.h" #include "database.h"
#include "dbghelp_safe.h" #include "dbghelp_safe.h"
#include "types.h" #include "types.h"
#include "label.h"
static DBGFUNCTIONS _dbgfunctions; static DBGFUNCTIONS _dbgfunctions;
@ -92,6 +93,15 @@ static int SymAutoComplete(const char* Search, char** Buffer, int MaxSymbols)
} }
} }
if (count < MaxSymbols) {
auto labels = LabelFindPrefix(prefix, MaxSymbols - count, caseSensitiveAutoComplete);
for (auto& label: labels) {
Buffer[count] = (char*)BridgeAlloc(label.size() + 1);
memcpy(Buffer[count], label.c_str(), label.size() + 1);
count++;
}
}
std::stable_sort(Buffer, Buffer + count, [](const char* a, const char* b) std::stable_sort(Buffer, Buffer + count, [](const char* a, const char* b)
{ {
return (caseSensitiveAutoComplete ? strcmp : StringUtils::hackicmp)(a, b) < 0; return (caseSensitiveAutoComplete ? strcmp : StringUtils::hackicmp)(a, b) < 0;

View File

@ -162,3 +162,27 @@ bool LabelGetInfo(duint Address, LABELSINFO* info)
return labels.Get(Labels::VaKey(Address), *info); return labels.Get(Labels::VaKey(Address), *info);
} }
std::vector<std::string> LabelFindPrefix(const std::string& prefix, int maxCount, bool isCaseSensitive)
{
std::vector<std::string> outputs;
auto cmp = isCaseSensitive? strncmp : _strnicmp;
size_t prefixSize = prefix.size();
labels.GetWhere([&](const LABELSINFO & value)
{
if ((int)outputs.size() >= maxCount)
{
return true;
}
if (cmp(prefix.c_str(), value.text.c_str(), prefixSize) != 0) {
return false;
}
outputs.push_back(value.text);
// continue to search all labels
return false;
});
return outputs;
}

View File

@ -20,5 +20,6 @@ void LabelCacheLoad(JSON root);
void LabelClear(); void LabelClear();
void LabelGetList(std::vector<LABELSINFO> & list); void LabelGetList(std::vector<LABELSINFO> & list);
bool LabelGetInfo(duint Address, LABELSINFO* info); bool LabelGetInfo(duint Address, LABELSINFO* info);
std::vector<std::string> LabelFindPrefix(const std::string& prefix, int maxCount, bool isCaseSensitive);
#endif // _LABEL_H #endif // _LABEL_H