Merge remote-tracking branch 'krobelus/textobject-count'

This commit is contained in:
Maxime Coste 2020-08-03 18:58:06 +10:00
commit 34baa56891
58 changed files with 182 additions and 82 deletions

View File

@ -494,7 +494,10 @@ select_sentence(const Context& context, const Selection& selection,
auto& buffer = context.buffer(); auto& buffer = context.buffer();
BufferIterator first = buffer.iterator_at(selection.cursor()); BufferIterator first = buffer.iterator_at(selection.cursor());
BufferIterator last;
for (++count; count > 0; --count)
{
if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin()) if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin())
{ {
BufferIterator prev_non_blank = first-1; BufferIterator prev_non_blank = first-1;
@ -504,7 +507,8 @@ select_sentence(const Context& context, const Selection& selection,
first = prev_non_blank; first = prev_non_blank;
} }
BufferIterator last = first; if (last == BufferIterator{})
last = first;
if (flags & ObjectFlags::ToBegin) if (flags & ObjectFlags::ToBegin)
{ {
@ -548,6 +552,7 @@ select_sentence(const Context& context, const Selection& selection,
--last; --last;
} }
} }
}
return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()} return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()}
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }
@ -558,7 +563,10 @@ select_paragraph(const Context& context, const Selection& selection,
{ {
auto& buffer = context.buffer(); auto& buffer = context.buffer();
BufferIterator first = buffer.iterator_at(selection.cursor()); BufferIterator first = buffer.iterator_at(selection.cursor());
BufferIterator last;
for (++count; count > 0; --count)
{
if (not (flags & ObjectFlags::ToEnd) and first.coord() > BufferCoord{0,1} and 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))) is_eol(*(first-1)) and first-1 != buffer.begin() and is_eol(*(first-2)))
--first; --first;
@ -566,8 +574,8 @@ select_paragraph(const Context& context, const Selection& selection,
first != buffer.begin() and (first+1) != buffer.end() and first != buffer.begin() and (first+1) != buffer.end() and
is_eol(*(first-1)) and is_eol(*first)) is_eol(*(first-1)) and is_eol(*first))
++first; ++first;
if (last == BufferIterator{})
BufferIterator last = first; last = first;
if ((flags & ObjectFlags::ToBegin) and first != buffer.begin()) if ((flags & ObjectFlags::ToBegin) and first != buffer.begin())
{ {
@ -604,6 +612,7 @@ select_paragraph(const Context& context, const Selection& selection,
} }
--last; --last;
} }
}
return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()} return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()}
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }

View File

@ -0,0 +1 @@
2}p

View File

@ -0,0 +1,7 @@
%(a
b)
c
d
e

View File

@ -0,0 +1,7 @@
'a
b
c
d
'

View File

@ -0,0 +1 @@
2}s

View File

@ -0,0 +1 @@
%(a b) c. d e. f.

View File

@ -0,0 +1 @@
'a b c. d e. '

View File

@ -0,0 +1 @@
2]p

View File

@ -0,0 +1,7 @@
%(a)
b
c
d
e

View File

@ -0,0 +1,7 @@
'a
b
c
d
'

View File

@ -0,0 +1 @@
9]p

View File

@ -0,0 +1,4 @@
%(a)
b
c

View File

@ -0,0 +1,5 @@
'a
b
c
'

View File

@ -0,0 +1 @@
<a-;>2]s

View File

@ -0,0 +1 @@
%(a b) c. d e. f g.

View File

@ -0,0 +1 @@
'a b c. d e. '

View File

@ -0,0 +1 @@
9]s

View File

@ -0,0 +1,3 @@
a b.
c d.

View File

@ -0,0 +1 @@
'a b.'

View File

@ -0,0 +1 @@
<a-;>2{p

View File

@ -0,0 +1,7 @@
a
b
c
%(d
e)

View File

@ -0,0 +1,5 @@
'b
c
d
e'

View File

@ -0,0 +1 @@
<a-;>2{s

View File

@ -0,0 +1 @@
a b. c d. e %(f g)

View File

@ -0,0 +1 @@
'c d. e f g'

View File

@ -0,0 +1 @@
2[p

View File

@ -0,0 +1,8 @@
a
b
c
d
%(e)
f

View File

@ -0,0 +1,5 @@
'b
c
d
e'

View File

@ -0,0 +1 @@
2[s

View File

@ -0,0 +1 @@
a b. c d. e %(f)

View File

@ -0,0 +1 @@
'c d. e f'

View File

@ -0,0 +1 @@
9[s

View File

@ -0,0 +1,3 @@
a b.
c d. %(e) f.

View File

@ -0,0 +1,3 @@
'a b.
c d.'