diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2020-07-19 21:48:52 +0200 |
|---|---|---|
| committer | Johannes Altmanninger <aclopte@gmail.com> | 2020-08-02 11:30:14 +0200 |
| commit | 266fe6f659aed2921c9aa024f2e07eb0e480d61f (patch) | |
| tree | 3a183a009ae09ff777fd031ae9939b5fe4391c22 /src | |
| parent | 98a1afcab07fc9253079e9a97acc6c2e1d3b2045 (diff) | |
Support count argument for [s and ]s
Part of #795
Diffstat (limited to 'src')
| -rw-r--r-- | src/selectors.cc | 89 |
1 files changed, 47 insertions, 42 deletions
diff --git a/src/selectors.cc b/src/selectors.cc index 58311689..a77a2379 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -494,58 +494,63 @@ select_sentence(const Context& context, const Selection& selection, auto& buffer = context.buffer(); BufferIterator first = buffer.iterator_at(selection.cursor()); + BufferIterator last; - if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin()) + for (++count; count > 0; --count) { - BufferIterator prev_non_blank = first-1; - skip_while_reverse(prev_non_blank, buffer.begin(), - [](char c) { return is_horizontal_blank(c) or is_eol(c); }); - if (is_end_of_sentence(*prev_non_blank)) - first = prev_non_blank; - } + if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin()) + { + BufferIterator prev_non_blank = first-1; + skip_while_reverse(prev_non_blank, buffer.begin(), + [](char c) { return is_horizontal_blank(c) or is_eol(c); }); + if (is_end_of_sentence(*prev_non_blank)) + first = prev_non_blank; + } - BufferIterator last = first; + if (last == BufferIterator{}) + last = first; - if (flags & ObjectFlags::ToBegin) - { - bool saw_non_blank = false; - while (first != buffer.begin()) + if (flags & ObjectFlags::ToBegin) { - char cur = *first; - char prev = *(first-1); - if (not is_horizontal_blank(cur)) - saw_non_blank = true; - if (is_eol(prev) and is_eol(cur) and first + 1 != buffer.end()) - { - ++first; - break; - } - else if (is_end_of_sentence(prev)) + bool saw_non_blank = false; + while (first != buffer.begin()) { - if (saw_non_blank) + char cur = *first; + char prev = *(first-1); + if (not is_horizontal_blank(cur)) + saw_non_blank = true; + if (is_eol(prev) and is_eol(cur) and first + 1 != buffer.end()) + { + ++first; break; - else if (flags & ObjectFlags::ToEnd) - last = first-1; + } + else if (is_end_of_sentence(prev)) + { + if (saw_non_blank) + break; + else if (flags & ObjectFlags::ToEnd) + last = first-1; + } + --first; } - --first; + skip_while(first, buffer.end(), is_horizontal_blank); } - skip_while(first, buffer.end(), is_horizontal_blank); - } - if (flags & ObjectFlags::ToEnd) - { - while (last != buffer.end()) - { - char cur = *last; - if (is_end_of_sentence(cur) or - (is_eol(cur) and (last+1 == buffer.end() or is_eol(*(last+1))))) - break; - ++last; - } - if (not (flags & ObjectFlags::Inner) and last != buffer.end()) + if (flags & ObjectFlags::ToEnd) { - ++last; - skip_while(last, buffer.end(), is_horizontal_blank); - --last; + while (last != buffer.end()) + { + char cur = *last; + if (is_end_of_sentence(cur) or + (is_eol(cur) and (last+1 == buffer.end() or is_eol(*(last+1))))) + break; + ++last; + } + if (not (flags & ObjectFlags::Inner) and last != buffer.end()) + { + ++last; + skip_while(last, buffer.end(), is_horizontal_blank); + --last; + } } } return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()} |
