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) - last = first; - while (first != buffer.begin()) - { - char cur = *first; - char prev = *(first-1); - if (is_eol(prev) and is_eol(cur)) - { - ++first; - break; - } + 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; - } - } - if (flags & ObjectFlags::ToEnd) - { - if (last != buffer.end() and is_eol(*last)) - ++last; - while (last != buffer.end()) + 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; + + if ((flags & ObjectFlags::ToBegin) and first != buffer.begin()) { - if (last != buffer.begin() and is_eol(*last) and is_eol(*(last-1))) - { - if (not (flags & ObjectFlags::Inner)) - skip_while(last, buffer.end(), + skip_while_reverse(first, buffer.begin(), [](Codepoint c){ return is_eol(c); }); - break; + if (flags & ObjectFlags::ToEnd) + last = first; + while (first != buffer.begin()) + { + char cur = *first; + char prev = *(first-1); + if (is_eol(prev) and is_eol(cur)) + { + ++first; + break; + } + --first; } - ++last; } - --last; + if (flags & ObjectFlags::ToEnd) + { + if (last != buffer.end() and is_eol(*last)) + ++last; + while (last != buffer.end()) + { + 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; + } } return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()} : Selection{last.coord(), first.coord()}; diff --git a/test/normal/object/end-extending/paragraph/count/cmd b/test/normal/object/end-extending/paragraph/count/cmd new file mode 100644 index 00000000..0f145764 --- /dev/null +++ b/test/normal/object/end-extending/paragraph/count/cmd @@ -0,0 +1 @@ +2}p diff --git a/test/normal/object/end-extending/paragraph/count/in b/test/normal/object/end-extending/paragraph/count/in new file mode 100644 index 00000000..369fa3df --- /dev/null +++ b/test/normal/object/end-extending/paragraph/count/in @@ -0,0 +1,7 @@ +%(a +b) + +c +d + +e diff --git a/test/normal/object/end-extending/paragraph/count/kak_quoted_selections b/test/normal/object/end-extending/paragraph/count/kak_quoted_selections new file mode 100644 index 00000000..1af89892 --- /dev/null +++ b/test/normal/object/end-extending/paragraph/count/kak_quoted_selections @@ -0,0 +1,7 @@ +'a +b + +c +d + +' diff --git a/test/normal/object/end/paragraph/count/cmd b/test/normal/object/end/paragraph/count/cmd new file mode 100644 index 00000000..23805695 --- /dev/null +++ b/test/normal/object/end/paragraph/count/cmd @@ -0,0 +1 @@ +2]p diff --git a/test/normal/object/end/paragraph/count/in b/test/normal/object/end/paragraph/count/in new file mode 100644 index 00000000..36097600 --- /dev/null +++ b/test/normal/object/end/paragraph/count/in @@ -0,0 +1,7 @@ +%(a) +b + +c +d + +e diff --git a/test/normal/object/end/paragraph/count/kak_quoted_selections b/test/normal/object/end/paragraph/count/kak_quoted_selections new file mode 100644 index 00000000..1af89892 --- /dev/null +++ b/test/normal/object/end/paragraph/count/kak_quoted_selections @@ -0,0 +1,7 @@ +'a +b + +c +d + +' diff --git a/test/normal/object/end/paragraph/to-buffer-end/cmd b/test/normal/object/end/paragraph/to-buffer-end/cmd new file mode 100644 index 00000000..f2801880 --- /dev/null +++ b/test/normal/object/end/paragraph/to-buffer-end/cmd @@ -0,0 +1 @@ +9]p diff --git a/test/normal/object/end/paragraph/to-buffer-end/in b/test/normal/object/end/paragraph/to-buffer-end/in new file mode 100644 index 00000000..e0766259 --- /dev/null +++ b/test/normal/object/end/paragraph/to-buffer-end/in @@ -0,0 +1,4 @@ +%(a) +b + +c diff --git a/test/normal/object/end/paragraph/to-buffer-end/kak_quoted_selections b/test/normal/object/end/paragraph/to-buffer-end/kak_quoted_selections new file mode 100644 index 00000000..3f303efe --- /dev/null +++ b/test/normal/object/end/paragraph/to-buffer-end/kak_quoted_selections @@ -0,0 +1,5 @@ +'a +b + +c +' diff --git a/test/normal/object/start-extending/paragraph/count/cmd b/test/normal/object/start-extending/paragraph/count/cmd new file mode 100644 index 00000000..4f718b51 --- /dev/null +++ b/test/normal/object/start-extending/paragraph/count/cmd @@ -0,0 +1 @@ +2{p diff --git a/test/normal/object/start-extending/paragraph/count/in b/test/normal/object/start-extending/paragraph/count/in new file mode 100644 index 00000000..37624a7c --- /dev/null +++ b/test/normal/object/start-extending/paragraph/count/in @@ -0,0 +1,7 @@ +a + +b + +c +%(d +e) diff --git a/test/normal/object/start-extending/paragraph/count/kak_quoted_selections b/test/normal/object/start-extending/paragraph/count/kak_quoted_selections new file mode 100644 index 00000000..850dbc36 --- /dev/null +++ b/test/normal/object/start-extending/paragraph/count/kak_quoted_selections @@ -0,0 +1,5 @@ +'b + +c +d +e' diff --git a/test/normal/object/start/paragraph/count/cmd b/test/normal/object/start/paragraph/count/cmd new file mode 100644 index 00000000..67d8b361 --- /dev/null +++ b/test/normal/object/start/paragraph/count/cmd @@ -0,0 +1 @@ +2[p diff --git a/test/normal/object/start/paragraph/count/in b/test/normal/object/start/paragraph/count/in new file mode 100644 index 00000000..c9f2b82c --- /dev/null +++ b/test/normal/object/start/paragraph/count/in @@ -0,0 +1,8 @@ +a + +b +c + +d +%(e) +f diff --git a/test/normal/object/start/paragraph/count/kak_quoted_selections b/test/normal/object/start/paragraph/count/kak_quoted_selections new file mode 100644 index 00000000..c827fb4f --- /dev/null +++ b/test/normal/object/start/paragraph/count/kak_quoted_selections @@ -0,0 +1,5 @@ +'b +c + +d +e'