CommandManager: fix completion of empty tokens

This commit is contained in:
Maxime Coste 2011-10-19 18:50:28 +00:00
parent d7f934b7ca
commit 712577b88e

View File

@ -79,18 +79,19 @@ Completions CommandManager::complete(const std::string& command_line, size_t cur
size_t token_to_complete = -1; size_t token_to_complete = -1;
for (size_t i = 0; i < tokens.size(); ++i) for (size_t i = 0; i < tokens.size(); ++i)
{ {
if (tokens[i].first < cursor_pos and tokens[i].second >= cursor_pos) if (tokens[i].first <= cursor_pos and tokens[i].second >= cursor_pos)
{ {
token_to_complete = i; token_to_complete = i;
break; break;
} }
} }
if (token_to_complete == 0) // command name completion if (token_to_complete == 0 or tokens.empty()) // command name completion
{ {
Completions result(tokens[0].first, cursor_pos); size_t cmd_start = tokens.empty() ? 0 : tokens[0].first;
std::string prefix = command_line.substr(tokens[0].first, Completions result(cmd_start, cursor_pos);
cursor_pos - tokens[0].first); std::string prefix = command_line.substr(cmd_start,
cursor_pos - cmd_start);
for (auto& command : m_commands) for (auto& command : m_commands)
{ {