Add , to fully selects lines selection is on.

This commit is contained in:
Maxime Coste 2011-11-21 18:53:22 +00:00
parent a1a57ea137
commit 2677fa7961
3 changed files with 23 additions and 1 deletions

View File

@ -574,7 +574,7 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> 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<char, std::function<void (Window& window, int count)>> 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<char, std::function<void (Window& window, int count)>> alt_keymap =

View File

@ -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;
}
}

View File

@ -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