diff --git a/src/main.cc b/src/main.cc index 312fbbe6..866bd50f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -469,6 +469,8 @@ std::unordered_map> 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 }, diff --git a/src/selectors.cc b/src/selectors.cc index 6b0ef4e9..c2f8e33b 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -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); +} + } diff --git a/src/selectors.hh b/src/selectors.hh index 453701f7..a53b30cc 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -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); }