From 90b92aed3c85e21c7d825a721cb4391deb91a698 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 12 Jul 2013 13:55:30 +0100 Subject: [PATCH] add support for tolower (`), toupper (~), and swap case become alt-` --- README.asciidoc | 4 +++- src/normal.cc | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index f1e760f3..069336c8 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -128,7 +128,9 @@ Changes * _r_: replace each character with the next entered one * _&_: align selection, align the last character of selections by inserting spaces before - * _~_: swap case + * _`_: to lower case + * _~_: to upper case + * _alt-`_: swap case Goto Commands ------------- diff --git a/src/normal.cc b/src/normal.cc index 1b2120f5..11e95305 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -211,20 +211,24 @@ void replace_with_char(Context& context) }); } -Codepoint swapped_case(Codepoint cp) +Codepoint to_lower(Codepoint cp) { return tolower(cp); } +Codepoint to_upper(Codepoint cp) { return toupper(cp); } + +Codepoint swap_case(Codepoint cp) { Codepoint res = std::tolower(cp); return res == cp ? std::toupper(cp) : res; } -void swap_case(Context& context) +template +void for_each_char(Context& context) { Editor& editor = context.editor(); std::vector sels = editor.selections_content(); for (auto& sel : sels) { for (auto& c : sel) - c = swapped_case(c); + c = func(c); } editor.insert(sels, InsertMode::Replace); } @@ -881,7 +885,10 @@ KeyMap keymap = { { Key::Modifiers::None, 'q' }, start_or_end_macro_recording }, { { Key::Modifiers::None, 'Q' }, replay_macro }, - { { Key::Modifiers::None, '~' }, swap_case }, + { { Key::Modifiers::None, '`' }, for_each_char }, + { { Key::Modifiers::None, '~' }, for_each_char }, + { { Key::Modifiers::Alt, '`' }, for_each_char }, + { { Key::Modifiers::None, '&' }, align }, { Key::Left, move },