diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-09-02 13:30:46 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-09-02 13:30:46 +0100 |
| commit | 96fc340a5c2ab5fa089c2786fcc9a35ff67ccda1 (patch) | |
| tree | 3be62448082c4c5f3529fd85bd6c4f796d093805 /src/normal.cc | |
| parent | 70cd671ef63c28678f73721c82ffb33cd3b662ad (diff) | |
add alt-& which aligns inserting spaces before selection start
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/normal.cc b/src/normal.cc index 72735438..802c8bbe 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -504,7 +504,7 @@ void split_lines(Context& context) res.push_back({line, {line, buffer[line].length()-1}}); res.push_back({max.line, max}); return res; - }); + }); } void join_select_spaces(Context& context) @@ -748,6 +748,7 @@ void jump(Context& context) context.editor().select(SelectionList{ jump }); } +template<bool insert_at_begin> void align(Context& context) { auto& selections = context.editor().selections(); @@ -757,12 +758,17 @@ void align(Context& context) CharCount max_col = 0; for (auto& sel : selections) + { + if (sel.first().line != sel.last().line) + throw runtime_error("align cannot work with multi line selections"); max_col = std::max(get_column(sel.last()), max_col); + } for (auto& sel : selections) { CharCount padding = max_col - get_column(sel.last()); - buffer.insert(buffer.iterator_at(sel.last()), String{ ' ', padding }); + auto it = buffer.iterator_at(insert_at_begin ? sel.min() : sel.last()); + buffer.insert(it, String{ ' ', padding }); } } @@ -931,9 +937,10 @@ KeyMap keymap = { { Key::Modifiers::None, '`' }, for_each_char<to_lower> }, { { Key::Modifiers::None, '~' }, for_each_char<to_upper> }, - { { Key::Modifiers::Alt, '`' }, for_each_char<swap_case> }, + { { Key::Modifiers::Alt, '`' }, for_each_char<swap_case> }, - { { Key::Modifiers::None, '&' }, align }, + { { Key::Modifiers::None, '&' }, align<false> }, + { { Key::Modifiers::Alt, '&' }, align<true> }, { Key::Left, move<CharCount, Backward> }, { Key::Down, move<LineCount, Forward> }, |
