summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-10-03 14:29:44 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-10-03 14:29:44 +0000
commitd99bcd7f2e097470d4574d0bf30d2c2609c9b77d (patch)
tree8c43722013054288681122d62d6ab1ed4d83f982 /src
parent01ac17ed04640a4d236c66f4a58d6d6634572018 (diff)
bind T and F as select_to_reverse non-inclusive and inclusive
Diffstat (limited to 'src')
-rw-r--r--src/main.cc2
-rw-r--r--src/selectors.cc15
-rw-r--r--src/selectors.hh2
3 files changed, 19 insertions, 0 deletions
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<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 },
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);
}