From 7a999b13bdd967c07da29273e9c03af3e3ddc989 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Tue, 29 Aug 2017 21:13:13 +0200 Subject: [PATCH] improved autocompletion in shell --- src/sparrowshell/sparrowshell.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sparrowshell/sparrowshell.cpp b/src/sparrowshell/sparrowshell.cpp index 2c52ac4..1d51954 100644 --- a/src/sparrowshell/sparrowshell.cpp +++ b/src/sparrowshell/sparrowshell.cpp @@ -70,9 +70,23 @@ SparrowShell::AutocompletionCallBack::AutocompletionCallBack(SparrowShell* shell void SparrowShell::AutocompletionCallBack::exec(){ std::string text = m_text_input_node->getText(); - std::vector result = m_shell->m_script->possibleCompletion(text); + std::vector results = m_shell->m_script->possibleCompletion(text); + + if (!results.empty()){ + std:: string common_prefix = results[0]; + for( auto result : results){ + int i = 0; + auto s1 = common_prefix.c_str(); + auto s2 = result.c_str(); + std::string cp; + while( (s1[i] && s2[i]) && (s1[i] == s2[i]) ) + cp.push_back(s1[i++]); + common_prefix = cp; + } + m_text_input_node->setText(common_prefix); + } std::string output = ""; - for(std::string& fun : result) + for(std::string& fun : results) output+=fun+" "; m_shell->out(output,glm::vec3(1,1,0)); }