Pass count to all object selectors

This commit is contained in:
Maxime Coste 2016-09-26 23:32:07 +01:00
parent 1e0ec182c1
commit fcb37cc754
3 changed files with 27 additions and 36 deletions

View File

@ -933,9 +933,9 @@ void select_object(Context& context, NormalParams params)
whole ? "" : (flags & ObjectFlags::ToBegin ? " begin" : " end")); whole ? "" : (flags & ObjectFlags::ToBegin ? " begin" : " end"));
}; };
const int level = params.count <= 0 ? 0 : params.count - 1; const int count = params.count <= 0 ? 0 : params.count - 1;
on_next_key_with_autoinfo(context, KeymapMode::Object, on_next_key_with_autoinfo(context, KeymapMode::Object,
[level](Key key, Context& context) { [count](Key key, Context& context) {
auto cp = key.codepoint().value_or((Codepoint)-1); auto cp = key.codepoint().value_or((Codepoint)-1);
if (cp == -1) if (cp == -1)
return; return;
@ -943,7 +943,7 @@ void select_object(Context& context, NormalParams params)
static constexpr struct static constexpr struct
{ {
Codepoint key; Codepoint key;
Selection (*func)(const Buffer&, const Selection&, ObjectFlags); Selection (*func)(const Buffer&, const Selection&, int, ObjectFlags);
} selectors[] = { } selectors[] = {
{ 'w', select_word<Word> }, { 'w', select_word<Word> },
{ 'W', select_word<WORD> }, { 'W', select_word<WORD> },
@ -952,16 +952,14 @@ void select_object(Context& context, NormalParams params)
{ ' ', select_whitespaces }, { ' ', select_whitespaces },
{ 'i', select_indent }, { 'i', select_indent },
{ 'n', select_number }, { 'n', select_number },
{ 'u', select_argument },
}; };
for (auto& sel : selectors) for (auto& sel : selectors)
{ {
if (cp == sel.key) if (cp == sel.key)
return select<mode>(context, std::bind(sel.func, _1, _2, flags)); return select<mode>(context, std::bind(sel.func, _1, _2, count, flags));
} }
if (cp == 'u')
return select<mode>(context, std::bind(select_argument, _1, _2, level, flags));
if (cp == ':') if (cp == ':')
{ {
const bool info = show_auto_info_ifn( const bool info = show_auto_info_ifn(
@ -971,7 +969,7 @@ void select_object(Context& context, NormalParams params)
context.input_handler().prompt( context.input_handler().prompt(
"object desc:", "", get_face("Prompt"), "object desc:", "", get_face("Prompt"),
PromptFlags::None, complete_nothing, PromptFlags::None, complete_nothing,
[level,info](StringView cmdline, PromptEvent event, Context& context) { [count,info](StringView cmdline, PromptEvent event, Context& context) {
if (event != PromptEvent::Change) if (event != PromptEvent::Change)
hide_auto_info_ifn(context, info); hide_auto_info_ifn(context, info);
if (event != PromptEvent::Validate) if (event != PromptEvent::Validate)
@ -982,7 +980,7 @@ void select_object(Context& context, NormalParams params)
throw runtime_error{"desc parsing failed, expected <open>,<close>"}; throw runtime_error{"desc parsing failed, expected <open>,<close>"};
return select<mode>(context, std::bind(select_surrounding, _1, _2, return select<mode>(context, std::bind(select_surrounding, _1, _2,
params[0], params[1], level, flags)); params[0], params[1], count, flags));
}); });
} }
@ -1007,7 +1005,7 @@ void select_object(Context& context, NormalParams params)
(sur.name != 0 and sur.name == cp)) (sur.name != 0 and sur.name == cp))
return select<mode>(context, std::bind(select_surrounding, _1, _2, return select<mode>(context, std::bind(select_surrounding, _1, _2,
sur.opening, sur.closing, sur.opening, sur.closing,
level, flags)); count, flags));
} }
if (is_punctuation(cp)) if (is_punctuation(cp))
@ -1015,7 +1013,7 @@ void select_object(Context& context, NormalParams params)
auto utf8cp = to_string(cp); auto utf8cp = to_string(cp);
return select<mode>(context, std::bind(select_surrounding, _1, _2, return select<mode>(context, std::bind(select_surrounding, _1, _2,
utf8cp, utf8cp, utf8cp, utf8cp,
level, flags)); count, flags));
} }
}, get_title(), }, get_title(),
"b,(,): parenthesis block\n" "b,(,): parenthesis block\n"

View File

@ -238,7 +238,7 @@ Selection select_to_reverse(const Buffer& buffer, const Selection& selection,
return utf8_range(begin, inclusive ? end : end+1); return utf8_range(begin, inclusive ? end : end+1);
} }
Selection select_number(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_number(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags)
{ {
auto is_number = [&](char c) { auto is_number = [&](char c) {
return (c >= '0' and c <= '9') or return (c >= '0' and c <= '9') or
@ -272,7 +272,7 @@ Selection select_number(const Buffer& buffer, const Selection& selection, Object
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }
Selection select_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_sentence(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags)
{ {
auto is_end_of_sentence = [](char c) { auto is_end_of_sentence = [](char c) {
return c == '.' or c == ';' or c == '!' or c == '?'; return c == '.' or c == ';' or c == '!' or c == '?';
@ -337,7 +337,7 @@ Selection select_sentence(const Buffer& buffer, const Selection& selection, Obje
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }
Selection select_paragraph(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_paragraph(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags)
{ {
BufferIterator first = buffer.iterator_at(selection.cursor()); BufferIterator first = buffer.iterator_at(selection.cursor());
@ -390,7 +390,7 @@ Selection select_paragraph(const Buffer& buffer, const Selection& selection, Obj
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }
Selection select_whitespaces(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_whitespaces(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags)
{ {
auto is_whitespace = [&](char c) { auto is_whitespace = [&](char c) {
return c == ' ' or c == '\t' or return c == ' ' or c == '\t' or
@ -419,7 +419,7 @@ Selection select_whitespaces(const Buffer& buffer, const Selection& selection, O
: Selection{last.coord(), first.coord()}; : Selection{last.coord(), first.coord()};
} }
Selection select_indent(const Buffer& buffer, const Selection& selection, ObjectFlags flags) Selection select_indent(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags)
{ {
auto get_indent = [](StringView str, int tabstop) { auto get_indent = [](StringView str, int tabstop) {
CharCount indent = 0; CharCount indent = 0;

View File

@ -144,9 +144,8 @@ enum class ObjectFlags
template<> struct WithBitOps<ObjectFlags> : std::true_type {}; template<> struct WithBitOps<ObjectFlags> : std::true_type {};
template<WordType word_type> template<WordType word_type>
Selection select_word(const Buffer& buffer, Selection select_word(const Buffer& buffer, const Selection& selection,
const Selection& selection, int count, ObjectFlags flags)
ObjectFlags flags)
{ {
Utf8Iterator first{buffer.iterator_at(selection.cursor()), buffer}; Utf8Iterator first{buffer.iterator_at(selection.cursor()), buffer};
Utf8Iterator last = first; Utf8Iterator last = first;
@ -187,28 +186,22 @@ Selection select_word(const Buffer& buffer,
: utf8_range(last, first); : utf8_range(last, first);
} }
Selection select_number(const Buffer& buffer, Selection select_number(const Buffer& buffer, const Selection& selection,
const Selection& selection, int count, ObjectFlags flags);
ObjectFlags flags);
Selection select_sentence(const Buffer& buffer, Selection select_sentence(const Buffer& buffer, const Selection& selection,
const Selection& selection, int count, ObjectFlags flags);
ObjectFlags flags);
Selection select_paragraph(const Buffer& buffer, Selection select_paragraph(const Buffer& buffer, const Selection& selection,
const Selection& selection, int count, ObjectFlags flags);
ObjectFlags flags);
Selection select_whitespaces(const Buffer& buffer, Selection select_whitespaces(const Buffer& buffer, const Selection& selection,
const Selection& selection, int count, ObjectFlags flags);
ObjectFlags flags);
Selection select_indent(const Buffer& buffer, Selection select_indent(const Buffer& buffer, const Selection& selection,
const Selection& selection, int count, ObjectFlags flags);
ObjectFlags flags);
Selection select_argument(const Buffer& buffer, Selection select_argument(const Buffer& buffer, const Selection& selection,
const Selection& selection,
int level, ObjectFlags flags); int level, ObjectFlags flags);
Selection select_lines(const Buffer& buffer, const Selection& selection); Selection select_lines(const Buffer& buffer, const Selection& selection);