use on_next_key in do_go and do_select_object

This commit is contained in:
Maxime Coste 2012-09-05 00:21:42 +02:00
parent b23425764e
commit 737ee8af24

View File

@ -123,22 +123,21 @@ template<bool append>
void do_go(Context& context)
{
int count = context.numeric_param();
Editor& editor = context.editor();
if (count != 0)
{
BufferIterator target =
editor.buffer().iterator_at_line_begin(count-1);
context.editor().buffer().iterator_at_line_begin(count-1);
editor.select(target);
context.editor().select(target);
if (context.has_window())
context.window().center_selection();
}
else
{
Key key = context.client().get_key();
context.client().on_next_key([](const Key& key, Context& context) {
if (key.modifiers != Key::Modifiers::None)
return;
Editor& editor = context.editor();
switch (key.key)
{
case 'g':
@ -160,7 +159,7 @@ void do_go(Context& context)
break;
}
}
}
});
}
void do_command(Context& context)
@ -288,6 +287,8 @@ void do_join(Context& context)
template<bool inner>
void do_select_object(Context& context)
{
context.client().on_next_key(
[](const Key& key, Context& context) {
typedef std::function<SelectionAndCaptures (const Selection&)> Selector;
static const std::unordered_map<Key, Selector> key_to_selector =
{
@ -305,10 +306,10 @@ void do_select_object(Context& context)
{ { Key::Modifiers::None, 'W' }, std::bind(select_whole_word<true>, _1, inner) },
};
Key key = context.client().get_key();
auto it = key_to_selector.find(key);
if (it != key_to_selector.end())
context.editor().select(it->second);
});
}
template<typename T>