bind T and F as select_to_reverse non-inclusive and inclusive

This commit is contained in:
Maxime Coste 2011-10-03 14:29:44 +00:00
parent 01ac17ed04
commit d99bcd7f2e
3 changed files with 19 additions and 0 deletions

View File

@ -469,6 +469,8 @@ std::unordered_map<char, std::function<void (Window& window, int count)>> keymap
{ 't', [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, false)); } },
{ 'f', [](Window& window, int count) { window.select(std::bind(select_to, _1, getch(), count, true)); } },
{ 'T', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, false)); } },
{ 'F', [](Window& window, int count) { window.select(std::bind(select_to_reverse, _1, getch(), count, true)); } },
{ 'd', do_erase },
{ 'c', do_change },

View File

@ -208,4 +208,19 @@ Selection select_to(const BufferIterator& cursor, char c, int count, bool inclus
return Selection(cursor, inclusive ? end : end-1);
}
Selection select_to_reverse(const BufferIterator& cursor, char c, int count, bool inclusive)
{
BufferIterator end = cursor;
do
{
--end;
skip_while_reverse(end, [c](char cur) { return not is_eol(cur) and cur != c; });
if (end.is_begin() or is_eol(*end))
return Selection(cursor, cursor);
}
while (--count > 0);
return Selection(cursor, inclusive ? end : end+1);
}
}

View File

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