From ac6f928ad4f47360eb90f2b0b8d098c6e70cce1b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 30 May 2022 19:27:18 +1000 Subject: [PATCH] Fix switch completion --- src/command_manager.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index c051a4bfe4..30684d85ca 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -760,15 +760,15 @@ Completions CommandManager::complete(const Context& context, auto& command = command_it->value; - auto is_switch = [](StringView s) { return s.substr(0_byte, 1_byte) == "-"; }; + const bool has_switches = not command.param_desc.switches.empty(); + auto is_switch = [=](StringView s) { return has_switches and s.substr(0_byte, 1_byte) == "-"; }; if (is_switch(token.content)) { auto switches = Kakoune::complete(token.content.substr(1_byte), pos_in_token, command.param_desc.switches | transform(&SwitchMap::Item::key)); - if (not switches.empty()) - return Completions{start+1, cursor_pos, std::move(switches)}; + return switches.empty() ? Completions{} : Completions{start+1, cursor_pos, std::move(switches)}; } if (not command.completer) return Completions{};