advanced auto complete added; first letter has to match, following letters have to appear in correct order. examples:

- 'twf' finds and completes into 'trapwriteif',
- 'g0' finds and completes into 'GRP0'
- 'em' finds 'ENAM0'&'ENAM1' and completes into 'ENAM'
This commit is contained in:
thrust26 2017-10-10 14:03:52 +02:00
parent 6c95d34ae3
commit c2325decb7
5 changed files with 28 additions and 10 deletions

View File

@ -189,6 +189,24 @@ namespace BSPF
{
return findIgnoreCase(s1, s2) != string::npos;
}
inline bool matches(const string& command, const string& in)
{
if(BSPF::startsWithIgnoreCase(command, in.substr(0, 1)))
{
size_t pos = 1;
for(int j = 1; j < in.size(); j++)
{
int found = BSPF::findIgnoreCase(command, in.substr(j, 1), pos);
if(found == string::npos)
return false;
pos += found + 1;
}
return true;
}
return false;
}
} // namespace BSPF
#endif

View File

@ -1279,23 +1279,23 @@ void CartDebug::getCompletions(const char* in, StringList& completions) const
{
// First scan system equates
for(uInt16 addr = 0x00; addr <= 0x0F; ++addr)
if(ourTIAMnemonicR[addr] && BSPF::startsWithIgnoreCase(ourTIAMnemonicR[addr], in))
if(ourTIAMnemonicR[addr] && BSPF::matches(ourTIAMnemonicR[addr], in))
completions.push_back(ourTIAMnemonicR[addr]);
for(uInt16 addr = 0x00; addr <= 0x3F; ++addr)
if(ourTIAMnemonicW[addr] && BSPF::startsWithIgnoreCase(ourTIAMnemonicW[addr], in))
if(ourTIAMnemonicW[addr] && BSPF::matches(ourTIAMnemonicW[addr], in))
completions.push_back(ourTIAMnemonicW[addr]);
for(uInt16 addr = 0; addr <= 0x297-0x280; ++addr)
if(ourIOMnemonic[addr] && BSPF::startsWithIgnoreCase(ourIOMnemonic[addr], in))
if(ourIOMnemonic[addr] && BSPF::matches(ourIOMnemonic[addr], in))
completions.push_back(ourIOMnemonic[addr]);
for(uInt16 addr = 0; addr <= 0x7F; ++addr)
if(ourZPMnemonic[addr] && BSPF::startsWithIgnoreCase(ourZPMnemonic[addr], in))
if(ourZPMnemonic[addr] && BSPF::matches(ourZPMnemonic[addr], in))
completions.push_back(ourZPMnemonic[addr]);
// Now scan user-defined labels
for(const auto& iter: myUserAddresses)
{
const char* l = iter.first.c_str();
if(BSPF::startsWithIgnoreCase(l, in))
if(BSPF::matches(l, in))
completions.push_back(l);
}
}

View File

@ -707,12 +707,12 @@ void Debugger::getCompletions(const char* in, StringList& list) const
for(const auto& iter: myFunctions)
{
const char* l = iter.first.c_str();
if(BSPF::startsWithIgnoreCase(l, in))
if(BSPF::matches(l, in))
list.push_back(l);
}
for(int i = 0; pseudo_registers[i][0] != 0; ++i)
if(BSPF::startsWithIgnoreCase(pseudo_registers[i][0], in))
if(BSPF::matches(pseudo_registers[i][0], in))
list.push_back(pseudo_registers[i][0]);
}

View File

@ -174,7 +174,7 @@ void DebuggerParser::getCompletions(const char* in, StringList& completions) con
// cerr << "Attempting to complete \"" << in << "\"" << endl;
for(int i = 0; i < kNumCommands; ++i)
{
if(BSPF::startsWithIgnoreCase(commands[i].cmdString.c_str(), in))
if(BSPF::matches(commands[i].cmdString, in))
completions.push_back(commands[i].cmdString);
}
}

View File

@ -501,7 +501,7 @@ void PromptWidget::loadConfig()
print(PROMPT);
// Take care of one-time debugger stuff
// fill the history from the saves breaks, traps and watches commands
// fill the history from the saved breaks, traps and watches commands
StringList history;
print(instance().debugger().autoExec(&history));
for(uInt32 i = 0; i < history.size(); i++)
@ -922,7 +922,7 @@ string PromptWidget::getCompletionPrefix(const StringList& completions, string p
{
if(s.length() < prefix.length())
return prefix; // current prefix is the best we're going to get
else if(!BSPF::startsWithIgnoreCase(s, prefix))
else if(!BSPF::matches(s, prefix))
{
prefix.erase(prefix.length()-1);
return prefix;