improved autocompletion in shell

This commit is contained in:
Lendemor 2017-08-29 21:13:13 +02:00
parent 33378ef8de
commit 7a999b13bd

View File

@ -70,9 +70,23 @@ SparrowShell::AutocompletionCallBack::AutocompletionCallBack(SparrowShell* shell
void SparrowShell::AutocompletionCallBack::exec(){ void SparrowShell::AutocompletionCallBack::exec(){
std::string text = m_text_input_node->getText(); std::string text = m_text_input_node->getText();
std::vector<std::string> result = m_shell->m_script->possibleCompletion(text); std::vector<std::string> 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 = ""; std::string output = "";
for(std::string& fun : result) for(std::string& fun : results)
output+=fun+" "; output+=fun+" ";
m_shell->out(output,glm::vec3(1,1,0)); m_shell->out(output,glm::vec3(1,1,0));
} }