diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-03-29 14:24:04 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-03-29 19:35:48 +0100 |
| commit | 585e64fd10066b4163aa0747d78240169d907098 (patch) | |
| tree | d3912b6cf235e8eb48ac62a0d04e3f016e3e3f86 | |
| parent | 01968cb96ec759bfad19507823d22431e6bf80e4 (diff) | |
add swap case support with the ~ key
| -rw-r--r-- | src/main.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main.cc b/src/main.cc index b0df788c..7c733f53 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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) { 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' }, replay_macro }, + + { { Key::Modifiers::None, '~' }, do_swap_case }, }; } |
