add swap case support with the ~ key

This commit is contained in:
Maxime Coste 2013-03-29 14:24:04 +01:00
parent 01968cb96e
commit 585e64fd10

View File

@ -121,6 +121,27 @@ void do_replace_with_char(Context& context)
}); });
} }
Codepoint swap_case(Codepoint cp)
{
if ('A' <= cp and cp <= 'Z')
return cp - 'A' + 'a';
if ('a' <= cp and cp <= 'z')
return cp - 'a' + 'A';
return cp;
}
void do_swap_case(Context& context)
{
Editor& editor = context.editor();
std::vector<String> sels = editor.selections_content();
for (auto& sel : sels)
{
for (auto& c : sel)
c = swap_case(c);
}
editor.insert(sels, InsertMode::Replace);
}
void do_command(Context& context) void do_command(Context& context)
{ {
context.input_handler().prompt( context.input_handler().prompt(
@ -674,6 +695,8 @@ std::unordered_map<Key, std::function<void (Context& context)>> keymap =
{ { Key::Modifiers::None, 'q' }, start_or_end_macro_recording }, { { Key::Modifiers::None, 'q' }, start_or_end_macro_recording },
{ { Key::Modifiers::None, 'Q' }, replay_macro }, { { Key::Modifiers::None, 'Q' }, replay_macro },
{ { Key::Modifiers::None, '~' }, do_swap_case },
}; };
} }