diff --git a/src/main.cc b/src/main.cc index 94ab9e45..e6234f94 100644 --- a/src/main.cc +++ b/src/main.cc @@ -574,7 +574,7 @@ std::unordered_map> keymap { 'W', [](Window& window, int count) { do { window.select(select_to_next_word, true); } while(--count > 0); } }, { 'E', [](Window& window, int count) { do { window.select(select_to_next_word_end, true); } while(--count > 0); } }, { 'B', [](Window& window, int count) { do { window.select(select_to_previous_word, true); } while(--count > 0); } }, - { 'x', [](Window& window, int count) { do { window.select(select_line); } while(--count > 0); } }, + { 'x', [](Window& window, int count) { do { window.select(select_line, false); } while(--count > 0); } }, { 'X', [](Window& window, int count) { do { window.select(select_line, true); } while(--count > 0); } }, { 'm', [](Window& window, int count) { window.select(select_matching); } }, { 'M', [](Window& window, int count) { window.select(select_matching, true); } }, @@ -582,6 +582,7 @@ std::unordered_map> keymap { 'n', [](Window& window, int count) { do_search_next(window); } }, { 'u', [](Window& window, int count) { do { if (not window.undo()) { print_status("nothing left to undo"); break; } } while(--count > 0); } }, { 'U', [](Window& window, int count) { do { if (not window.redo()) { print_status("nothing left to redo"); break; } } while(--count > 0); } }, + { ',', [](Window& window, int count) { window.multi_select(select_whole_lines); } }, }; std::unordered_map> alt_keymap = diff --git a/src/selectors.cc b/src/selectors.cc index bd7cc550..6a0ee218 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -279,4 +279,22 @@ Selection select_to_eol_reverse(const BufferIterator& cursor) return Selection(cursor, end.is_begin() ? end : end+1); } +SelectionList select_whole_lines(const Selection& selection) +{ + BufferIterator first = selection.first(); + BufferIterator last = selection.last(); + BufferIterator& to_line_start = first <= last ? first : last; + BufferIterator& to_line_end = first <= last ? last : first; + + skip_while_reverse(to_line_start, [](char cur) { return not is_eol(cur); }); + skip_while(to_line_end, [](char cur) { return not is_eol(cur); }); + + if (to_line_start != to_line_end) + ++to_line_start; + + SelectionList result; + result.push_back(Selection(first, last)); + return result; +} + } diff --git a/src/selectors.hh b/src/selectors.hh index 4887a747..16ff095b 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -20,6 +20,9 @@ Selection select_to_reverse(const BufferIterator& cursor, char c, int count, boo Selection select_to_eol(const BufferIterator& cursor); Selection select_to_eol_reverse(const BufferIterator& cursor); + +SelectionList select_whole_lines(const Selection& selection); + } #endif // selectors_hh_INCLUDED