Merge pull request #3681 from dabeibao/development
Goto dialog: add completion for labels
This commit is contained in:
commit
cca598427f
|
@ -32,6 +32,7 @@
|
|||
#include "database.h"
|
||||
#include "dbghelp_safe.h"
|
||||
#include "types.h"
|
||||
#include "label.h"
|
||||
|
||||
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)
|
||||
{
|
||||
return (caseSensitiveAutoComplete ? strcmp : StringUtils::hackicmp)(a, b) < 0;
|
||||
|
|
|
@ -162,3 +162,27 @@ bool LabelGetInfo(duint Address, LABELSINFO* 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;
|
||||
}
|
||||
|
|
|
@ -20,5 +20,6 @@ void LabelCacheLoad(JSON root);
|
|||
void LabelClear();
|
||||
void LabelGetList(std::vector<LABELSINFO> & list);
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue