Merge remote-tracking branch 'krobelus/textobject-count'
This commit is contained in:
commit
34baa56891
173
src/selectors.cc
173
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;
|
||||
}
|
||||
|
||||
BufferIterator last = first;
|
||||
|
||||
if (flags & ObjectFlags::ToBegin)
|
||||
{
|
||||
bool saw_non_blank = false;
|
||||
while (first != buffer.begin())
|
||||
if (not (flags & ObjectFlags::ToEnd) and first != buffer.begin())
|
||||
{
|
||||
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())
|
||||
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 (last == BufferIterator{})
|
||||
last = first;
|
||||
|
||||
if (flags & ObjectFlags::ToBegin)
|
||||
{
|
||||
bool saw_non_blank = false;
|
||||
while (first != buffer.begin())
|
||||
{
|
||||
++first;
|
||||
break;
|
||||
}
|
||||
else if (is_end_of_sentence(prev))
|
||||
{
|
||||
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())
|
||||
if (flags & ObjectFlags::ToEnd)
|
||||
{
|
||||
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;
|
||||
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()}
|
||||
|
@ -558,51 +563,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()};
|
||||
|
|
1
test/normal/object/end-extending/paragraph/count/cmd
Normal file
1
test/normal/object/end-extending/paragraph/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
2}p
|
7
test/normal/object/end-extending/paragraph/count/in
Normal file
7
test/normal/object/end-extending/paragraph/count/in
Normal file
|
@ -0,0 +1,7 @@
|
|||
%(a
|
||||
b)
|
||||
|
||||
c
|
||||
d
|
||||
|
||||
e
|
|
@ -0,0 +1,7 @@
|
|||
'a
|
||||
b
|
||||
|
||||
c
|
||||
d
|
||||
|
||||
'
|
1
test/normal/object/end-extending/sentence/count/cmd
Normal file
1
test/normal/object/end-extending/sentence/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
2}s
|
1
test/normal/object/end-extending/sentence/count/in
Normal file
1
test/normal/object/end-extending/sentence/count/in
Normal file
|
@ -0,0 +1 @@
|
|||
%(a b) c. d e. f.
|
|
@ -0,0 +1 @@
|
|||
'a b c. d e. '
|
1
test/normal/object/end/paragraph/count/cmd
Normal file
1
test/normal/object/end/paragraph/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
2]p
|
7
test/normal/object/end/paragraph/count/in
Normal file
7
test/normal/object/end/paragraph/count/in
Normal file
|
@ -0,0 +1,7 @@
|
|||
%(a)
|
||||
b
|
||||
|
||||
c
|
||||
d
|
||||
|
||||
e
|
|
@ -0,0 +1,7 @@
|
|||
'a
|
||||
b
|
||||
|
||||
c
|
||||
d
|
||||
|
||||
'
|
1
test/normal/object/end/paragraph/to-buffer-end/cmd
Normal file
1
test/normal/object/end/paragraph/to-buffer-end/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
9]p
|
4
test/normal/object/end/paragraph/to-buffer-end/in
Normal file
4
test/normal/object/end/paragraph/to-buffer-end/in
Normal file
|
@ -0,0 +1,4 @@
|
|||
%(a)
|
||||
b
|
||||
|
||||
c
|
|
@ -0,0 +1,5 @@
|
|||
'a
|
||||
b
|
||||
|
||||
c
|
||||
'
|
1
test/normal/object/end/sentence/count/cmd
Normal file
1
test/normal/object/end/sentence/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-;>2]s
|
1
test/normal/object/end/sentence/count/in
Normal file
1
test/normal/object/end/sentence/count/in
Normal file
|
@ -0,0 +1 @@
|
|||
%(a b) c. d e. f g.
|
|
@ -0,0 +1 @@
|
|||
'a b c. d e. '
|
1
test/normal/object/end/sentence/to-buffer-end/cmd
Normal file
1
test/normal/object/end/sentence/to-buffer-end/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
9]s
|
3
test/normal/object/end/sentence/to-buffer-end/in
Normal file
3
test/normal/object/end/sentence/to-buffer-end/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
a b.
|
||||
|
||||
c d.
|
|
@ -0,0 +1 @@
|
|||
'a b.'
|
1
test/normal/object/start-extending/paragraph/count/cmd
Normal file
1
test/normal/object/start-extending/paragraph/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-;>2{p
|
7
test/normal/object/start-extending/paragraph/count/in
Normal file
7
test/normal/object/start-extending/paragraph/count/in
Normal file
|
@ -0,0 +1,7 @@
|
|||
a
|
||||
|
||||
b
|
||||
|
||||
c
|
||||
%(d
|
||||
e)
|
|
@ -0,0 +1,5 @@
|
|||
'b
|
||||
|
||||
c
|
||||
d
|
||||
e'
|
1
test/normal/object/start-extending/sentence/count/cmd
Normal file
1
test/normal/object/start-extending/sentence/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
<a-;>2{s
|
1
test/normal/object/start-extending/sentence/count/in
Normal file
1
test/normal/object/start-extending/sentence/count/in
Normal file
|
@ -0,0 +1 @@
|
|||
a b. c d. e %(f g)
|
|
@ -0,0 +1 @@
|
|||
'c d. e f g'
|
1
test/normal/object/start/paragraph/count/cmd
Normal file
1
test/normal/object/start/paragraph/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
2[p
|
8
test/normal/object/start/paragraph/count/in
Normal file
8
test/normal/object/start/paragraph/count/in
Normal file
|
@ -0,0 +1,8 @@
|
|||
a
|
||||
|
||||
b
|
||||
c
|
||||
|
||||
d
|
||||
%(e)
|
||||
f
|
|
@ -0,0 +1,5 @@
|
|||
'b
|
||||
c
|
||||
|
||||
d
|
||||
e'
|
1
test/normal/object/start/sentence/count/cmd
Normal file
1
test/normal/object/start/sentence/count/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
2[s
|
1
test/normal/object/start/sentence/count/in
Normal file
1
test/normal/object/start/sentence/count/in
Normal file
|
@ -0,0 +1 @@
|
|||
a b. c d. e %(f)
|
|
@ -0,0 +1 @@
|
|||
'c d. e f'
|
1
test/normal/object/start/sentence/to-buffer-begin/cmd
Normal file
1
test/normal/object/start/sentence/to-buffer-begin/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
9[s
|
3
test/normal/object/start/sentence/to-buffer-begin/in
Normal file
3
test/normal/object/start/sentence/to-buffer-begin/in
Normal file
|
@ -0,0 +1,3 @@
|
|||
a b.
|
||||
|
||||
c d. %(e) f.
|
|
@ -0,0 +1,3 @@
|
|||
'a b.
|
||||
|
||||
c d.'
|
Loading…
Reference in New Issue
Block a user