use on_next_key in do_go and do_select_object
This commit is contained in:
parent
b23425764e
commit
737ee8af24
99
src/main.cc
99
src/main.cc
|
@ -123,44 +123,43 @@ template<bool append>
|
||||||
void do_go(Context& context)
|
void do_go(Context& context)
|
||||||
{
|
{
|
||||||
int count = context.numeric_param();
|
int count = context.numeric_param();
|
||||||
Editor& editor = context.editor();
|
|
||||||
if (count != 0)
|
if (count != 0)
|
||||||
{
|
{
|
||||||
BufferIterator target =
|
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())
|
if (context.has_window())
|
||||||
context.window().center_selection();
|
context.window().center_selection();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
context.client().on_next_key([](const Key& key, Context& context) {
|
||||||
Key key = context.client().get_key();
|
if (key.modifiers != Key::Modifiers::None)
|
||||||
if (key.modifiers != Key::Modifiers::None)
|
return;
|
||||||
return;
|
|
||||||
|
|
||||||
switch (key.key)
|
Editor& editor = context.editor();
|
||||||
{
|
switch (key.key)
|
||||||
case 'g':
|
{
|
||||||
case 't':
|
case 'g':
|
||||||
editor.select(editor.buffer().begin());
|
case 't':
|
||||||
break;
|
editor.select(editor.buffer().begin());
|
||||||
case 'l':
|
break;
|
||||||
case 'L':
|
case 'l':
|
||||||
editor.select(select_to_eol, append);
|
case 'L':
|
||||||
break;
|
editor.select(select_to_eol, append);
|
||||||
case 'h':
|
break;
|
||||||
case 'H':
|
case 'h':
|
||||||
editor.select(select_to_eol_reverse, append);
|
case 'H':
|
||||||
break;
|
editor.select(select_to_eol_reverse, append);
|
||||||
case 'b':
|
break;
|
||||||
{
|
case 'b':
|
||||||
const Buffer& buf = editor.buffer();
|
{
|
||||||
editor.select(buf.iterator_at_line_begin(buf.line_count() - 1));
|
const Buffer& buf = editor.buffer();
|
||||||
break;
|
editor.select(buf.iterator_at_line_begin(buf.line_count() - 1));
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_command(Context& context)
|
void do_command(Context& context)
|
||||||
|
@ -288,27 +287,29 @@ void do_join(Context& context)
|
||||||
template<bool inner>
|
template<bool inner>
|
||||||
void do_select_object(Context& context)
|
void do_select_object(Context& context)
|
||||||
{
|
{
|
||||||
typedef std::function<SelectionAndCaptures (const Selection&)> Selector;
|
context.client().on_next_key(
|
||||||
static const std::unordered_map<Key, Selector> key_to_selector =
|
[](const Key& key, Context& context) {
|
||||||
{
|
typedef std::function<SelectionAndCaptures (const Selection&)> Selector;
|
||||||
{ { Key::Modifiers::None, '(' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
|
static const std::unordered_map<Key, Selector> key_to_selector =
|
||||||
{ { Key::Modifiers::None, ')' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
|
{
|
||||||
{ { Key::Modifiers::None, 'b' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
|
{ { Key::Modifiers::None, '(' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
|
||||||
{ { Key::Modifiers::None, '{' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
|
{ { Key::Modifiers::None, ')' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
|
||||||
{ { Key::Modifiers::None, '}' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
|
{ { Key::Modifiers::None, 'b' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '(', ')' }, inner) },
|
||||||
{ { Key::Modifiers::None, 'B' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
|
{ { Key::Modifiers::None, '{' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
|
||||||
{ { Key::Modifiers::None, '[' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
|
{ { Key::Modifiers::None, '}' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
|
||||||
{ { Key::Modifiers::None, ']' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
|
{ { Key::Modifiers::None, 'B' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '{', '}' }, inner) },
|
||||||
{ { Key::Modifiers::None, '<' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
|
{ { Key::Modifiers::None, '[' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
|
||||||
{ { Key::Modifiers::None, '>' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
|
{ { Key::Modifiers::None, ']' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '[', ']' }, inner) },
|
||||||
{ { Key::Modifiers::None, 'w' }, std::bind(select_whole_word<false>, _1, inner) },
|
{ { Key::Modifiers::None, '<' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
|
||||||
{ { Key::Modifiers::None, 'W' }, std::bind(select_whole_word<true>, _1, inner) },
|
{ { Key::Modifiers::None, '>' }, std::bind(select_surrounding, _1, std::pair<char, char>{ '<', '>' }, inner) },
|
||||||
};
|
{ { Key::Modifiers::None, 'w' }, std::bind(select_whole_word<false>, _1, inner) },
|
||||||
|
{ { 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);
|
||||||
auto it = key_to_selector.find(key);
|
if (it != key_to_selector.end())
|
||||||
if (it != key_to_selector.end())
|
context.editor().select(it->second);
|
||||||
context.editor().select(it->second);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user