1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 15:23:29 +03:00

Support count argument for [s and ]s

Part of #795
This commit is contained in:
Johannes Altmanninger 2020-07-19 21:48:52 +02:00
parent 98a1afcab0
commit 266fe6f659
19 changed files with 73 additions and 44 deletions

View File

@ -494,58 +494,63 @@ 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;
if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin()) for (++count; count > 0; --count)
{ {
BufferIterator prev_non_blank = first-1; if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin())
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 (flags & ObjectFlags::ToBegin)
{
bool saw_non_blank = false;
while (first != buffer.begin())
{ {
char cur = *first; BufferIterator prev_non_blank = first-1;
char prev = *(first-1); skip_while_reverse(prev_non_blank, buffer.begin(),
if (not is_horizontal_blank(cur)) [](char c) { return is_horizontal_blank(c) or is_eol(c); });
saw_non_blank = true; if (is_end_of_sentence(*prev_non_blank))
if (is_eol(prev) and is_eol(cur) and first + 1 != buffer.end()) first = prev_non_blank;
}
if (last == BufferIterator{})
last = first;
if (flags & ObjectFlags::ToBegin)
{
bool saw_non_blank = false;
while (first != buffer.begin())
{ {
++first; char cur = *first;
break; char prev = *(first-1);
} if (not is_horizontal_blank(cur))
else if (is_end_of_sentence(prev)) saw_non_blank = true;
{ if (is_eol(prev) and is_eol(cur) and first + 1 != buffer.end())
if (saw_non_blank) {
++first;
break; 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)
}
if (flags & ObjectFlags::ToEnd)
{
while (last != buffer.end())
{ {
char cur = *last; while (last != buffer.end())
if (is_end_of_sentence(cur) or {
(is_eol(cur) and (last+1 == buffer.end() or is_eol(*(last+1))))) char cur = *last;
break; if (is_end_of_sentence(cur) or
++last; (is_eol(cur) and (last+1 == buffer.end() or is_eol(*(last+1)))))
} break;
if (not (flags & ObjectFlags::Inner) and last != buffer.end()) ++last;
{ }
++last; if (not (flags & ObjectFlags::Inner) and last != buffer.end())
skip_while(last, buffer.end(), is_horizontal_blank); {
--last; ++last;
skip_while(last, buffer.end(), is_horizontal_blank);
--last;
}
} }
} }
return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()} return (flags & ObjectFlags::ToEnd) ? Selection{first.coord(), last.coord()}

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 @@
<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{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[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.'