From 610acb3c0edce75b9d552a88fe063f2924ca5a57 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 27 Sep 2011 14:27:48 +0000 Subject: [PATCH] Selectors: add a count argument to select_to --- src/main.cc | 4 ++-- src/selectors.cc | 18 ++++++++++++------ src/selectors.hh | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main.cc b/src/main.cc index eeddbe56..67a13363 100644 --- a/src/main.cc +++ b/src/main.cc @@ -428,8 +428,8 @@ std::unordered_map> keymap { 'L', [](Window& window, int count) { window.select(true, std::bind(move_select, std::ref(window), _1, WindowCoord(0, std::max(count,1)))); } }, - { 't', [](Window& window, int count) { window.select(false, std::bind(select_to, _1, getch(), false)); } }, - { 'f', [](Window& window, int count) { window.select(false, std::bind(select_to, _1, getch(), true)); } }, + { '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(), count, true)); } }, { 'd', do_erase }, { 'c', do_change }, diff --git a/src/selectors.cc b/src/selectors.cc index 8d1cd95a..6b0ef4e9 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -193,13 +193,19 @@ Selection select_matching(const BufferIterator& 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; - skip_while(end, [c](char cur) { return not is_eol(cur) and cur != c; }); - if (not is_eol(*end)) - return Selection(cursor, inclusive ? end : end-1); - return Selection(cursor, cursor); + BufferIterator end = cursor; + do + { + ++end; + skip_while(end, [c](char cur) { return not is_eol(cur) and cur != c; }); + if (end.is_end() 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 0fe6136b..453701f7 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -12,7 +12,7 @@ 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, bool inclusive); +Selection select_to(const BufferIterator& cursor, char c, int count, bool inclusive); }