Select previous sentence or paragraph if selecting backward from the first char
[s and [p on the first char of a sentence or paragraph will select the previous sentence or paragraph.
This commit is contained in:
parent
968922055b
commit
ac90839c3d
|
@ -226,6 +226,16 @@ static bool is_end_of_sentence(char c)
|
||||||
Selection select_whole_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
|
Selection select_whole_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
|
||||||
{
|
{
|
||||||
BufferIterator first = buffer.iterator_at(selection.cursor());
|
BufferIterator first = buffer.iterator_at(selection.cursor());
|
||||||
|
|
||||||
|
if (not (flags & ObjectFlags::ToEnd))
|
||||||
|
{
|
||||||
|
BufferIterator prev_non_blank = first-1;
|
||||||
|
skip_while_reverse(prev_non_blank, buffer.begin(),
|
||||||
|
[](char c) { return is_blank(c) or is_eol(c); });
|
||||||
|
if (is_end_of_sentence(*prev_non_blank))
|
||||||
|
first = prev_non_blank;
|
||||||
|
}
|
||||||
|
|
||||||
BufferIterator last = first;
|
BufferIterator last = first;
|
||||||
|
|
||||||
if (flags & ObjectFlags::ToBegin)
|
if (flags & ObjectFlags::ToBegin)
|
||||||
|
@ -277,9 +287,14 @@ Selection select_whole_sentence(const Buffer& buffer, const Selection& selection
|
||||||
Selection select_whole_paragraph(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
|
Selection select_whole_paragraph(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
|
||||||
{
|
{
|
||||||
BufferIterator first = buffer.iterator_at(selection.cursor());
|
BufferIterator first = buffer.iterator_at(selection.cursor());
|
||||||
|
|
||||||
|
if (not (flags & ObjectFlags::ToEnd) and buffer.offset(first.coord()) > 1 and
|
||||||
|
*(first-1) == '\n' and *(first-2) == '\n')
|
||||||
|
--first;
|
||||||
|
|
||||||
BufferIterator last = first;
|
BufferIterator last = first;
|
||||||
|
|
||||||
if (flags & ObjectFlags::ToBegin and first != buffer.begin())
|
if ((flags & ObjectFlags::ToBegin) and first != buffer.begin())
|
||||||
{
|
{
|
||||||
skip_while_reverse(first, buffer.begin(), is_eol);
|
skip_while_reverse(first, buffer.begin(), is_eol);
|
||||||
if (flags & ObjectFlags::ToEnd)
|
if (flags & ObjectFlags::ToEnd)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user