From 3cc42b1dc545d5990e05d63f46ecdf470623eeb7 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Tue, 10 Oct 2017 14:47:29 +0200 Subject: [PATCH] resulting string from incomplete autocomplete fixed --- src/debugger/gui/PromptWidget.cxx | 34 +++++++++++++++---------------- src/debugger/gui/PromptWidget.hxx | 2 +- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/debugger/gui/PromptWidget.cxx b/src/debugger/gui/PromptWidget.cxx index 945f25571..eaa7ef268 100644 --- a/src/debugger/gui/PromptWidget.cxx +++ b/src/debugger/gui/PromptWidget.cxx @@ -238,7 +238,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod) completionList = list[0]; for(uInt32 i = 1; i < list.size(); ++i) completionList += " " + list[i]; - prefix = getCompletionPrefix(list, str); + prefix = getCompletionPrefix(list); } else { @@ -263,7 +263,7 @@ bool PromptWidget::handleKeyDown(StellaKey key, StellaMod mod) completionList = list[0]; for(uInt32 i = 1; i < list.size(); ++i) completionList += " " + list[i]; - prefix = getCompletionPrefix(list, str + lastDelimPos + 1); + prefix = getCompletionPrefix(list); } 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 - // Once a mismatch is found or length is past one of the strings, we're done - // 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(;;) + // Find the largest match at the beginning of the completions provided + for(int len = 1;; len++) { - for(const auto& s: completions) + for(const auto& s1 : completions) { - if(s.length() < prefix.length()) - return prefix; // current prefix is the best we're going to get - else if(!BSPF::matches(s, prefix)) + if(s1.length() < len) { - prefix.erase(prefix.length()-1); - return prefix; + return s1.substr(0, len - 1); + } + 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; } } diff --git a/src/debugger/gui/PromptWidget.hxx b/src/debugger/gui/PromptWidget.hxx index 95e3a6142..3e967898b 100644 --- a/src/debugger/gui/PromptWidget.hxx +++ b/src/debugger/gui/PromptWidget.hxx @@ -85,7 +85,7 @@ class PromptWidget : public Widget, public CommandSender private: // 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: enum {