Selectors: add a count argument to select_to

This commit is contained in:
Maxime Coste 2011-09-27 14:27:48 +00:00
parent 01018a5eac
commit 610acb3c0e
3 changed files with 15 additions and 9 deletions

View File

@ -428,8 +428,8 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 'L', [](Window& window, int count) { window.select(true, std::bind(move_select, std::ref(window), _1, { 'L', [](Window& window, int count) { window.select(true, std::bind(move_select, std::ref(window), _1,
WindowCoord(0, std::max(count,1)))); } }, WindowCoord(0, std::max(count,1)))); } },
{ 't', [](Window& window, int count) { window.select(false, std::bind(select_to, _1, getch(), false)); } }, { 't', [](Window& window, int count) { window.select(false, std::bind(select_to, _1, getch(), count, false)); } },
{ 'f', [](Window& window, int count) { window.select(false, std::bind(select_to, _1, getch(), true)); } }, { 'f', [](Window& window, int count) { window.select(false, std::bind(select_to, _1, getch(), count, true)); } },
{ 'd', do_erase }, { 'd', do_erase },
{ 'c', do_change }, { 'c', do_change },

View File

@ -193,13 +193,19 @@ Selection select_matching(const BufferIterator& cursor)
return Selection(cursor, cursor); return Selection(cursor, cursor);
} }
Selection select_to(const BufferIterator& cursor, char c, bool inclusive) Selection select_to(const BufferIterator& cursor, char c, int count, bool inclusive)
{ {
BufferIterator end = cursor + 1; BufferIterator end = cursor;
do
{
++end;
skip_while(end, [c](char cur) { return not is_eol(cur) and cur != c; }); skip_while(end, [c](char cur) { return not is_eol(cur) and cur != c; });
if (not is_eol(*end)) if (end.is_end() or is_eol(*end))
return Selection(cursor, inclusive ? end : end-1);
return Selection(cursor, cursor); return Selection(cursor, cursor);
}
while (--count > 0);
return Selection(cursor, inclusive ? end : end-1);
} }
} }

View File

@ -12,7 +12,7 @@ Selection select_to_previous_word(const BufferIterator& cursor);
Selection select_line(const BufferIterator& cursor); Selection select_line(const BufferIterator& cursor);
Selection move_select(Window& window, const BufferIterator& cursor, const WindowCoord& offset); Selection move_select(Window& window, const BufferIterator& cursor, const WindowCoord& offset);
Selection select_matching(const BufferIterator& cursor); Selection select_matching(const BufferIterator& cursor);
Selection select_to(const BufferIterator& cursor, char c, bool inclusive); Selection select_to(const BufferIterator& cursor, char c, int count, bool inclusive);
} }