Merge remote-tracking branch 'Delapouite/rename-completions'

This commit is contained in:
Maxime Coste 2018-09-22 22:02:58 +10:00
commit 3f4c86b12f

View File

@ -157,6 +157,15 @@ static Completions complete_buffer_name(const Context& context, CompletionFlags
return { 0, cursor_pos, res }; return { 0, cursor_pos, res };
} }
auto make_single_word_completer(std::function<String (const Context&)> func)
{
return make_completer(
[func](const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos) -> Completions {
auto candidate = { func(context) };
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, candidate) }; });
}
auto buffer_completer = make_completer(complete_buffer_name<false>); auto buffer_completer = make_completer(complete_buffer_name<false>);
auto other_buffer_completer = make_completer(complete_buffer_name<true>); auto other_buffer_completer = make_completer(complete_buffer_name<true>);
@ -673,7 +682,7 @@ const CommandDesc rename_buffer_cmd = {
single_param, single_param,
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, make_single_word_completer([](const Context& context){ return context.buffer().display_name(); }),
[](const ParametersParser& parser, Context& context, const ShellContext&) [](const ParametersParser& parser, Context& context, const ShellContext&)
{ {
if (not context.buffer().set_name(parser[0])) if (not context.buffer().set_name(parser[0]))
@ -2120,7 +2129,7 @@ const CommandDesc rename_client_cmd = {
single_param, single_param,
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, make_single_word_completer([](const Context& context){ return context.name(); }),
[](const ParametersParser& parser, Context& context, const ShellContext&) [](const ParametersParser& parser, Context& context, const ShellContext&)
{ {
const String& name = parser[0]; const String& name = parser[0];
@ -2196,7 +2205,7 @@ const CommandDesc rename_session_cmd = {
single_param, single_param,
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, make_single_word_completer([](const Context&){ return Server::instance().session(); }),
[](const ParametersParser& parser, Context&, const ShellContext&) [](const ParametersParser& parser, Context&, const ShellContext&)
{ {
if (not Server::instance().rename_session(parser[0])) if (not Server::instance().rename_session(parser[0]))