add paragraph (p) object
This commit is contained in:
parent
4bb3863f95
commit
b69c9ea753
|
@ -210,6 +210,7 @@ object you want.
|
||||||
* _w_: select the whole word
|
* _w_: select the whole word
|
||||||
* _W_: select the whole WORD
|
* _W_: select the whole WORD
|
||||||
* _s_: select the sentence
|
* _s_: select the sentence
|
||||||
|
* _p_: select the paragraph
|
||||||
|
|
||||||
Registers
|
Registers
|
||||||
---------
|
---------
|
||||||
|
|
|
@ -524,6 +524,7 @@ void select_object(Context& context)
|
||||||
{ { Key::Modifiers::None, 'w' }, std::bind(select_whole_word<false>, _1, flags & SurroundFlags::Inner) },
|
{ { Key::Modifiers::None, 'w' }, std::bind(select_whole_word<false>, _1, flags & SurroundFlags::Inner) },
|
||||||
{ { Key::Modifiers::None, 'W' }, std::bind(select_whole_word<true>, _1, flags & SurroundFlags::Inner) },
|
{ { Key::Modifiers::None, 'W' }, std::bind(select_whole_word<true>, _1, flags & SurroundFlags::Inner) },
|
||||||
{ { Key::Modifiers::None, 's' }, std::bind(select_whole_sentence, _1, flags & SurroundFlags::Inner) },
|
{ { Key::Modifiers::None, 's' }, std::bind(select_whole_sentence, _1, flags & SurroundFlags::Inner) },
|
||||||
|
{ { Key::Modifiers::None, 'p' }, std::bind(select_whole_paragraph, _1, flags & SurroundFlags::Inner) },
|
||||||
};
|
};
|
||||||
|
|
||||||
auto it = key_to_selector.find(key);
|
auto it = key_to_selector.find(key);
|
||||||
|
|
|
@ -421,6 +421,40 @@ Selection select_whole_sentence(const Selection& selection, bool inner)
|
||||||
return Selection{first, last};
|
return Selection{first, last};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Selection select_whole_paragraph(const Selection& selection, bool inner)
|
||||||
|
{
|
||||||
|
BufferIterator first = selection.last();
|
||||||
|
|
||||||
|
while (not is_begin(first))
|
||||||
|
{
|
||||||
|
char cur = *first;
|
||||||
|
char prev = *(first-1);
|
||||||
|
if (is_eol(prev) and is_eol(cur))
|
||||||
|
{
|
||||||
|
++first;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
--first;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferIterator last = first;
|
||||||
|
while (not is_end(last))
|
||||||
|
{
|
||||||
|
char cur = *last;
|
||||||
|
char prev = *(last-1);
|
||||||
|
if (is_eol(cur) and is_eol(prev))
|
||||||
|
{
|
||||||
|
if (not inner)
|
||||||
|
skip_while(last, is_eol);
|
||||||
|
--last;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++last;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Selection{first, last};
|
||||||
|
}
|
||||||
|
|
||||||
Selection select_whole_lines(const Selection& selection)
|
Selection select_whole_lines(const Selection& selection)
|
||||||
{
|
{
|
||||||
// no need to be utf8 aware for is_eol as we only use \n as line seperator
|
// no need to be utf8 aware for is_eol as we only use \n as line seperator
|
||||||
|
|
|
@ -28,6 +28,7 @@ Selection select_to_eol_reverse(const Selection& selection);
|
||||||
template<bool punctuation_is_word>
|
template<bool punctuation_is_word>
|
||||||
Selection select_whole_word(const Selection& selection, bool inner);
|
Selection select_whole_word(const Selection& selection, bool inner);
|
||||||
Selection select_whole_sentence(const Selection& selection, bool inner);
|
Selection select_whole_sentence(const Selection& selection, bool inner);
|
||||||
|
Selection select_whole_paragraph(const Selection& selection, bool inner);
|
||||||
Selection select_whole_lines(const Selection& selection);
|
Selection select_whole_lines(const Selection& selection);
|
||||||
Selection select_whole_buffer(const Selection& selection);
|
Selection select_whole_buffer(const Selection& selection);
|
||||||
Selection trim_partial_lines(const Selection& selection);
|
Selection trim_partial_lines(const Selection& selection);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user