add alt-& which aligns inserting spaces before selection start

This commit is contained in:
Maxime Coste 2013-09-02 13:30:46 +01:00
parent 70cd671ef6
commit 96fc340a5c

View File

@ -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 });
}
}
@ -933,7 +939,8 @@ KeyMap keymap =
{ { Key::Modifiers::None, '~' }, for_each_char<to_upper> },
{ { 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> },