diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2011-10-19 18:50:28 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2011-10-19 18:50:28 +0000 |
| commit | 712577b88ec00ef4a7d86afccf748e2ec8546dd1 (patch) | |
| tree | 7553fe615072a6eef1dad7e7102f21aedd18a827 /src/command_manager.cc | |
| parent | d7f934b7ca1b37dd5710e0b058a6ac1f4fe1c9d9 (diff) | |
CommandManager: fix completion of empty tokens
Diffstat (limited to 'src/command_manager.cc')
| -rw-r--r-- | src/command_manager.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc index 791b1f94..b1722f3f 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -79,18 +79,19 @@ Completions CommandManager::complete(const std::string& command_line, size_t cur size_t token_to_complete = -1; 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; 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); - std::string prefix = command_line.substr(tokens[0].first, - cursor_pos - tokens[0].first); + size_t cmd_start = tokens.empty() ? 0 : tokens[0].first; + Completions result(cmd_start, cursor_pos); + std::string prefix = command_line.substr(cmd_start, + cursor_pos - cmd_start); for (auto& command : m_commands) { |
