From 96fc340a5c2ab5fa089c2786fcc9a35ff67ccda1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 2 Sep 2013 13:30:46 +0100 Subject: add alt-& which aligns inserting spaces before selection start --- src/normal.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/normal.cc') 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 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 }, { { Key::Modifiers::None, '~' }, for_each_char }, - { { Key::Modifiers::Alt, '`' }, for_each_char }, + { { Key::Modifiers::Alt, '`' }, for_each_char }, - { { Key::Modifiers::None, '&' }, align }, + { { Key::Modifiers::None, '&' }, align }, + { { Key::Modifiers::Alt, '&' }, align }, { Key::Left, move }, { Key::Down, move }, -- cgit v1.2.3