resulting string from incomplete autocomplete fixed

This commit is contained in:
thrust26 2017-10-10 14:47:29 +02:00
parent 3e6fe633f3
commit 3cc42b1dc5
2 changed files with 17 additions and 19 deletions

View File

@ -238,7 +238,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
completionList = list[0]; completionList = list[0];
for(uInt32 i = 1; i < list.size(); ++i) for(uInt32 i = 1; i < list.size(); ++i)
completionList += " " + list[i]; completionList += " " + list[i];
prefix = getCompletionPrefix(list, str); prefix = getCompletionPrefix(list);
} }
else else
{ {
@ -263,7 +263,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod)
completionList = list[0]; completionList = list[0];
for(uInt32 i = 1; i < list.size(); ++i) for(uInt32 i = 1; i < list.size(); ++i)
completionList += " " + list[i]; completionList += " " + list[i];
prefix = getCompletionPrefix(list, str + lastDelimPos + 1); prefix = getCompletionPrefix(list);
} }
if(list.size() == 1) if(list.size() == 1)
@ -911,28 +911,26 @@ bool PromptWidget::saveBuffer(const FilesystemNode& file)
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string PromptWidget::getCompletionPrefix(const StringList& completions, string prefix) string PromptWidget::getCompletionPrefix(const StringList& completions)
{ {
// Search for prefix in every string, progressively growing it // Find the largest match at the beginning of the completions provided
// Once a mismatch is found or length is past one of the strings, we're done for(int len = 1;; len++)
// We *could* use the longest common string algorithm, but for the lengths
// of the strings we're dealing with, it's probably not worth it
for(;;)
{ {
for(const auto& s: completions) for(const auto& s1 : completions)
{ {
if(s.length() < prefix.length()) if(s1.length() < len)
return prefix; // current prefix is the best we're going to get
else if(!BSPF::matches(s, prefix))
{ {
prefix.erase(prefix.length()-1); return s1.substr(0, len - 1);
return prefix; }
string find = s1.substr(0, len);
for(const auto& s2 : completions)
{
if(!BSPF::matches(s2, find))
{
return s1.substr(0, len - 1);
}
} }
} }
if(completions[0].length() > prefix.length())
prefix = completions[0].substr(0, prefix.length() + 1);
else
return prefix;
} }
} }

View File

@ -85,7 +85,7 @@ class PromptWidget : public Widget, public CommandSender
private: private:
// Get the longest prefix (initially 's') that is in every string in the list // Get the longest prefix (initially 's') that is in every string in the list
string getCompletionPrefix(const StringList& completions, string s); string getCompletionPrefix(const StringList& completions);
private: private:
enum { enum {