summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-04-30 14:29:18 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-04-30 14:29:18 +0200
commitb69c9ea7534b6001e55d7befcb62d6f4c4385f93 (patch)
tree0543406d13e3e1a6b8116a405f8ea9dca580abf3 /src
parent4bb3863f954e565908caad023300001f30e73948 (diff)
add paragraph (p) object
Diffstat (limited to 'src')
-rw-r--r--src/normal.cc1
-rw-r--r--src/selectors.cc34
-rw-r--r--src/selectors.hh1
3 files changed, 36 insertions, 0 deletions
diff --git a/src/normal.cc b/src/normal.cc
index b7995762..8d7b19cb 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -524,6 +524,7 @@ void select_object(Context& context)
{ { Key::Modifiers::None, 'w' }, std::bind(select_whole_word<false>, _1, flags & SurroundFlags::Inner) },
{ { Key::Modifiers::None, 'W' }, std::bind(select_whole_word<true>, _1, flags & SurroundFlags::Inner) },
{ { Key::Modifiers::None, 's' }, std::bind(select_whole_sentence, _1, flags & SurroundFlags::Inner) },
+ { { Key::Modifiers::None, 'p' }, std::bind(select_whole_paragraph, _1, flags & SurroundFlags::Inner) },
};
auto it = key_to_selector.find(key);
diff --git a/src/selectors.cc b/src/selectors.cc
index d16b1b43..f5095832 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -421,6 +421,40 @@ Selection select_whole_sentence(const Selection& selection, bool inner)
return Selection{first, last};
}
+Selection select_whole_paragraph(const Selection& selection, bool inner)
+{
+ BufferIterator first = selection.last();
+
+ while (not is_begin(first))
+ {
+ char cur = *first;
+ char prev = *(first-1);
+ if (is_eol(prev) and is_eol(cur))
+ {
+ ++first;
+ break;
+ }
+ --first;
+ }
+
+ BufferIterator last = first;
+ while (not is_end(last))
+ {
+ char cur = *last;
+ char prev = *(last-1);
+ if (is_eol(cur) and is_eol(prev))
+ {
+ if (not inner)
+ skip_while(last, is_eol);
+ --last;
+ break;
+ }
+ ++last;
+ }
+
+ return Selection{first, last};
+}
+
Selection select_whole_lines(const Selection& selection)
{
// no need to be utf8 aware for is_eol as we only use \n as line seperator
diff --git a/src/selectors.hh b/src/selectors.hh
index 07c19494..f58dfc07 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -28,6 +28,7 @@ Selection select_to_eol_reverse(const Selection& selection);
template<bool punctuation_is_word>
Selection select_whole_word(const Selection& selection, bool inner);
Selection select_whole_sentence(const Selection& selection, bool inner);
+Selection select_whole_paragraph(const Selection& selection, bool inner);
Selection select_whole_lines(const Selection& selection);
Selection select_whole_buffer(const Selection& selection);
Selection trim_partial_lines(const Selection& selection);