diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2020-07-19 15:34:59 +0200 |
|---|---|---|
| committer | Johannes Altmanninger <aclopte@gmail.com> | 2020-08-02 11:30:14 +0200 |
| commit | 98a1afcab07fc9253079e9a97acc6c2e1d3b2045 (patch) | |
| tree | 133e0a7602127a9590b9e730db3ac8ea624e0b0e /src/selectors.cc | |
| parent | 581f17970da05c1fdaf75c994b8f4c666443c85f (diff) | |
Support count argument for [p and ]p
Part of #795
Diffstat (limited to 'src/selectors.cc')
| -rw-r--r-- | src/selectors.cc | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/src/selectors.cc b/src/selectors.cc index c7e126b3..58311689 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -558,51 +558,55 @@ select_paragraph(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.coord() > BufferCoord{0,1} and - is_eol(*(first-1)) and first-1 != buffer.begin() and is_eol(*(first-2))) - --first; - else if ((flags & ObjectFlags::ToEnd) and - first != buffer.begin() and (first+1) != buffer.end() and - is_eol(*(first-1)) and is_eol(*first)) - ++first; - - BufferIterator last = first; - - if ((flags & ObjectFlags::ToBegin) and first != buffer.begin()) + for (++count; count > 0; --count) { - skip_while_reverse(first, buffer.begin(), - [](Codepoint c){ return is_eol(c); }); - if (flags & ObjectFlags::ToEnd) + if (not (flags & ObjectFlags::ToEnd) and first.coord() > BufferCoord{0,1} and + is_eol(*(first-1)) and first-1 != buffer.begin() and is_eol(*(first-2))) + --first; + else if ((flags & ObjectFlags::ToEnd) and + first != buffer.begin() and (first+1) != buffer.end() and + is_eol(*(first-1)) and is_eol(*first)) + ++first; + if (last == BufferIterator{}) last = first; - while (first != buffer.begin()) + + if ((flags & ObjectFlags::ToBegin) and first != buffer.begin()) { - char cur = *first; - char prev = *(first-1); - if (is_eol(prev) and is_eol(cur)) + skip_while_reverse(first, buffer.begin(), + [](Codepoint c){ return is_eol(c); }); + if (flags & ObjectFlags::ToEnd) + last = first; + while (first != buffer.begin()) { - ++first; - break; + char cur = *first; + char prev = *(first-1); + if (is_eol(prev) and is_eol(cur)) + { + ++first; + break; + } + --first; } - --first; } - } - if (flags & ObjectFlags::ToEnd) - { - if (last != buffer.end() and is_eol(*last)) - ++last; - while (last != buffer.end()) + if (flags & ObjectFlags::ToEnd) { - if (last != buffer.begin() and is_eol(*last) and is_eol(*(last-1))) + if (last != buffer.end() and is_eol(*last)) + ++last; + while (last != buffer.end()) { - if (not (flags & ObjectFlags::Inner)) - skip_while(last, buffer.end(), - [](Codepoint c){ return is_eol(c); }); - break; + if (last != buffer.begin() and is_eol(*last) and is_eol(*(last-1))) + { + if (not (flags & ObjectFlags::Inner)) + skip_while(last, buffer.end(), + [](Codepoint c){ return is_eol(c); }); + break; + } + ++last; } - ++last; + --last; } - --last; } return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()} : Selection{last.coord(), first.coord()}; |
