Move WORD text object to <a-w>

It improves consistency and it looked like there was support for that
change on github.
Fixes #1861
This commit is contained in:
Maxime Coste 2018-03-10 00:25:19 +11:00
parent f801d0064a
commit 4584ecac77
9 changed files with 22 additions and 18 deletions

View File

@ -612,7 +612,7 @@ the wanted object:
*w*:: *w*::
select the whole word select the whole word
*W*:: *<a-w>*::
select the whole WORD select the whole WORD
*s*:: *s*::

View File

@ -48,7 +48,8 @@ static const char* startup_info =
" * '*' Does not strip whitespaces anymore, use built-in '_' to strip them\n" " * '*' Does not strip whitespaces anymore, use built-in '_' to strip them\n"
" * 'l' on eol will go to next line, 'h' on first char will go to previous\n" " * 'l' on eol will go to next line, 'h' on first char will go to previous\n"
" * selections merging behaviour is now a bit more complex again\n" " * selections merging behaviour is now a bit more complex again\n"
" * 'x' will only jump to next line if full line is already selected\n"; " * 'x' will only jump to next line if full line is already selected\n"
" * WORD text object moved to <a-w> instead of W for consistency\n";
struct startup_error : runtime_error struct startup_error : runtime_error
{ {

View File

@ -1181,17 +1181,16 @@ void select_object(Context& context, NormalParams params)
const int count = 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,
[count](Key key, Context& context) { [count](Key key, Context& context) {
if (not key.codepoint() or key == Key::Escape) if (key == Key::Escape)
return; return;
const auto cp = *key.codepoint();
static constexpr struct ObjectType static constexpr struct ObjectType
{ {
Codepoint key; Key key;
Optional<Selection> (*func)(const Context&, const Selection&, int, ObjectFlags); Optional<Selection> (*func)(const Context&, const Selection&, int, ObjectFlags);
} selectors[] = { } selectors[] = {
{ 'w', select_word<Word> }, { 'w', select_word<Word> },
{ 'W', select_word<WORD> }, { alt('w'), select_word<WORD> },
{ 's', select_sentence }, { 's', select_sentence },
{ 'p', select_paragraph }, { 'p', select_paragraph },
{ ' ', select_whitespaces }, { ' ', select_whitespaces },
@ -1199,12 +1198,12 @@ void select_object(Context& context, NormalParams params)
{ 'n', select_number }, { 'n', select_number },
{ 'u', select_argument }, { 'u', select_argument },
}; };
auto obj_it = find(selectors | transform(std::mem_fn(&ObjectType::key)), cp).base(); auto obj_it = find(selectors | transform(std::mem_fn(&ObjectType::key)), key).base();
if (obj_it != std::end(selectors)) if (obj_it != std::end(selectors))
return select_and_set_last<mode>( return select_and_set_last<mode>(
context, std::bind(obj_it->func, _1, _2, count, flags)); context, std::bind(obj_it->func, _1, _2, count, flags));
if (cp == 'c') if (key == 'c')
{ {
const bool info = show_auto_info_ifn( const bool info = show_auto_info_ifn(
"Enter object desc", "Enter object desc",
@ -1253,9 +1252,9 @@ void select_object(Context& context, NormalParams params)
{ '`', '`', 'g' }, { '`', '`', 'g' },
}; };
auto pair_it = find_if(surrounding_pairs, auto pair_it = find_if(surrounding_pairs,
[cp](const SurroundingPair& s) { [key](const SurroundingPair& s) {
return s.opening == cp or s.closing == cp or return key == s.opening or key == s.closing or
(s.name != 0 and s.name == cp); (s.name != 0 and key == s.name);
}); });
if (pair_it != std::end(surrounding_pairs)) if (pair_it != std::end(surrounding_pairs))
return select_and_set_last<mode>( return select_and_set_last<mode>(
@ -1264,6 +1263,10 @@ void select_object(Context& context, NormalParams params)
Regex{format("\\Q{}", pair_it->closing), RegexCompileFlags::Backward}, Regex{format("\\Q{}", pair_it->closing), RegexCompileFlags::Backward},
count, flags)); count, flags));
if (not key.codepoint())
return;
const Codepoint cp = *key.codepoint();
if (is_punctuation(cp) or cp == '_') if (is_punctuation(cp) or cp == '_')
{ {
auto re = Regex{"\\Q" + to_string(cp), RegexCompileFlags::Backward}; auto re = Regex{"\\Q" + to_string(cp), RegexCompileFlags::Backward};
@ -1281,7 +1284,7 @@ void select_object(Context& context, NormalParams params)
{{'\'','q'}, "single quote string"}, {{'\'','q'}, "single quote string"},
{{'`','g'}, "grave quote string"}, {{'`','g'}, "grave quote string"},
{{'w'}, "word"}, {{'w'}, "word"},
{{'W'}, "WORD"}, {{alt('w')}, "WORD"},
{{'s'}, "sentence"}, {{'s'}, "sentence"},
{{'p'}, "paragraph"}, {{'p'}, "paragraph"},
{{' '}, "whitespaces"}, {{' '}, "whitespaces"},

View File

@ -1 +1 @@
<a-a>W <a-a><a-w>

View File

@ -1 +1 @@
}W }<a-w>

View File

@ -1 +1 @@
]W ]<a-w>

View File

@ -1 +1 @@
<a-i>W <a-i><a-w>

View File

@ -1 +1 @@
{W {<a-w>

View File

@ -1 +1 @@
[W [<a-w>