add ' ' for whitespaces object
This commit is contained in:
parent
847fc0512b
commit
d5b1605df5
|
@ -339,6 +339,7 @@ object you want.
|
||||||
* _W_: select the whole WORD
|
* _W_: select the whole WORD
|
||||||
* _s_: select the sentence
|
* _s_: select the sentence
|
||||||
* _p_: select the paragraph
|
* _p_: select the paragraph
|
||||||
|
* _␣_: select the whitespaces
|
||||||
* _i_: select the current indentation block
|
* _i_: select the current indentation block
|
||||||
* _n_: select the number
|
* _n_: select the number
|
||||||
|
|
||||||
|
|
|
@ -839,6 +839,7 @@ void select_object(Context& context, int param)
|
||||||
{ 'W', select_word<WORD> },
|
{ 'W', select_word<WORD> },
|
||||||
{ 's', select_sentence },
|
{ 's', select_sentence },
|
||||||
{ 'p', select_paragraph },
|
{ 'p', select_paragraph },
|
||||||
|
{ ' ', select_whitespaces },
|
||||||
{ 'i', select_indent },
|
{ 'i', select_indent },
|
||||||
{ 'n', select_number },
|
{ 'n', select_number },
|
||||||
};
|
};
|
||||||
|
@ -880,6 +881,7 @@ void select_object(Context& context, int param)
|
||||||
"W: WORD \n"
|
"W: WORD \n"
|
||||||
"s: sentence \n"
|
"s: sentence \n"
|
||||||
"p: paragraph \n"
|
"p: paragraph \n"
|
||||||
|
"␣: whitespaces \n"
|
||||||
"i: indent \n");
|
"i: indent \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -377,6 +377,35 @@ static CharCount get_indent(const String& str, int tabstop)
|
||||||
return indent;
|
return indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Selection select_whitespaces(const Buffer& buffer, const Selection& selection, ObjectFlags flags)
|
||||||
|
{
|
||||||
|
auto is_whitespace = [&](char c) {
|
||||||
|
return c == ' ' or c == '\t' or
|
||||||
|
(not (flags & ObjectFlags::Inner) and c == '\n');
|
||||||
|
};
|
||||||
|
BufferIterator first = buffer.iterator_at(selection.cursor());
|
||||||
|
BufferIterator last = first;
|
||||||
|
if (flags & ObjectFlags::ToBegin)
|
||||||
|
{
|
||||||
|
if (is_whitespace(*first))
|
||||||
|
{
|
||||||
|
skip_while_reverse(first, buffer.begin(), is_whitespace);
|
||||||
|
if (not is_whitespace(*first))
|
||||||
|
++first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flags & ObjectFlags::ToEnd)
|
||||||
|
{
|
||||||
|
if (is_whitespace(*last))
|
||||||
|
{
|
||||||
|
skip_while(last, buffer.end(), is_whitespace);
|
||||||
|
--last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (flags & ObjectFlags::ToEnd) ? utf8_range(first, last)
|
||||||
|
: utf8_range(last, first);
|
||||||
|
}
|
||||||
|
|
||||||
static bool is_only_whitespaces(const String& str)
|
static bool is_only_whitespaces(const String& str)
|
||||||
{
|
{
|
||||||
auto it = str.begin();
|
auto it = str.begin();
|
||||||
|
|
|
@ -212,6 +212,10 @@ Selection select_paragraph(const Buffer& buffer,
|
||||||
const Selection& selection,
|
const Selection& selection,
|
||||||
ObjectFlags flags);
|
ObjectFlags flags);
|
||||||
|
|
||||||
|
Selection select_whitespaces(const Buffer& buffer,
|
||||||
|
const Selection& selection,
|
||||||
|
ObjectFlags flags);
|
||||||
|
|
||||||
Selection select_indent(const Buffer& buffer,
|
Selection select_indent(const Buffer& buffer,
|
||||||
const Selection& selection,
|
const Selection& selection,
|
||||||
ObjectFlags flags);
|
ObjectFlags flags);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user