diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-11-21 23:20:21 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-11-22 09:55:32 +0000 |
| commit | b83414ddf7f49184acd62df2672def0b3c1f8ea5 (patch) | |
| tree | 508af0b167cfc014c7b8c8942a97398955be2232 /src/normal.cc | |
| parent | 90ea3023fe25be011c00fd7ed6c75c6d4214139a (diff) | |
add alt-& for align indent
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/normal.cc b/src/normal.cc index 694736ac..e6e101e7 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -877,6 +877,40 @@ void align(Context& context, int) } } +void align_indent(Context& context, int selection) +{ + auto& editor = context.editor(); + auto& buffer = context.buffer(); + auto& selections = editor.selections(); + std::vector<LineCount> lines; + for (auto sel : selections) + { + for (LineCount l = sel.min().line; l < sel.max().line + 1; ++l) + lines.push_back(l); + } + if (selection > selections.size()) + throw runtime_error("invalid selection index"); + if (selection == 0) + selection = editor.main_selection_index() + 1; + + const String& line = buffer[selections[selection-1].min().line]; + auto it = line.begin(); + while (it != line.end() and is_horizontal_blank(*it)) + ++it; + const String indent{line.begin(), it}; + + scoped_edition edition{editor}; + for (auto& l : lines) + { + auto& line = buffer[l]; + ByteCount i = 0; + while (i < line.length() and is_horizontal_blank(line[i])) + ++i; + buffer.erase(buffer.iterator_at(l), buffer.iterator_at({l, i})); + buffer.insert(buffer.iterator_at(l), indent); + } +} + template<typename T> class Repeated { @@ -1048,6 +1082,7 @@ KeyMap keymap = { alt('`'), for_each_char<swap_case> }, { '&', align }, + { alt('&'), align_indent }, { Key::Left, move<CharCount, Backward> }, { Key::Down, move<LineCount, Forward> }, |
