From 712577b88ec00ef4a7d86afccf748e2ec8546dd1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 19 Oct 2011 18:50:28 +0000 Subject: [PATCH] CommandManager: fix completion of empty tokens --- src/command_manager.cc | 11 ++++++----- 1 file 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) {