summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2011-09-22 14:35:28 +0000
committerMaxime Coste <frrrwww@gmail.com>2011-09-22 14:35:28 +0000
commitc3faeb6c058da1790b03b2c50bbba1f7ecc572d3 (patch)
tree8928592978c0614279b176bc27b2a472c0940bce /src
parent0f4f201b6d9069f56c5f9ca7121dfd4def0dd759 (diff)
Selectors: add select_to which selects until a given character on current line
Diffstat (limited to 'src')
-rw-r--r--src/main.cc2
-rw-r--r--src/selectors.cc9
-rw-r--r--src/selectors.hh1
3 files changed, 12 insertions, 0 deletions
diff --git a/src/main.cc b/src/main.cc
index 7ab02efd..00fb8749 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -368,6 +368,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), std::placeholders::_1,
WindowCoord(0, std::max(count,1)))); } },
+ { 't', [](Window& window, int count) { window.select(false, std::bind(select_to, std::placeholders::_1, getch())); } },
+
{ 'd', [](Window& window, int count) { window.erase(); window.empty_selections(); } },
{ 'c', [](Window& window, int count) { window.erase(); do_insert(window); } },
{ 'i', [](Window& window, int count) { do_insert(window); } },
diff --git a/src/selectors.cc b/src/selectors.cc
index d3f6835c..c8377079 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -158,4 +158,13 @@ Selection select_matching(const BufferIterator& cursor)
return Selection(cursor, cursor);
}
+Selection select_to(const BufferIterator& cursor, char c)
+{
+ 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, end);
+ return Selection(cursor, cursor);
+}
+
}
diff --git a/src/selectors.hh b/src/selectors.hh
index d304227a..0d9adc64 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -12,6 +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);
}