From 3f7bf82cdeb68bd3e73dcff4545bf23045fcfb73 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 7 Jan 2013 18:53:27 +0100 Subject: Support for selecting to surrounding object begin/end with [ and ] --- src/main.cc | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/main.cc') diff --git a/src/main.cc b/src/main.cc index f21dcde6..418ead97 100644 --- a/src/main.cc +++ b/src/main.cc @@ -311,7 +311,7 @@ void do_deindent(Context& context) editor.erase(); } -template +template void do_select_object(Context& context) { context.input_handler().on_next_key( @@ -319,18 +319,18 @@ void do_select_object(Context& context) typedef std::function Selector; static const std::unordered_map key_to_selector = { - { { Key::Modifiers::None, '(' }, std::bind(select_surrounding, _1, CodepointPair{ '(', ')' }, inner) }, - { { Key::Modifiers::None, ')' }, std::bind(select_surrounding, _1, CodepointPair{ '(', ')' }, inner) }, - { { Key::Modifiers::None, 'b' }, std::bind(select_surrounding, _1, CodepointPair{ '(', ')' }, inner) }, - { { Key::Modifiers::None, '{' }, std::bind(select_surrounding, _1, CodepointPair{ '{', '}' }, inner) }, - { { Key::Modifiers::None, '}' }, std::bind(select_surrounding, _1, CodepointPair{ '{', '}' }, inner) }, - { { Key::Modifiers::None, 'B' }, std::bind(select_surrounding, _1, CodepointPair{ '{', '}' }, inner) }, - { { Key::Modifiers::None, '[' }, std::bind(select_surrounding, _1, CodepointPair{ '[', ']' }, inner) }, - { { Key::Modifiers::None, ']' }, std::bind(select_surrounding, _1, CodepointPair{ '[', ']' }, inner) }, - { { Key::Modifiers::None, '<' }, std::bind(select_surrounding, _1, CodepointPair{ '<', '>' }, inner) }, - { { Key::Modifiers::None, '>' }, std::bind(select_surrounding, _1, CodepointPair{ '<', '>' }, inner) }, - { { Key::Modifiers::None, 'w' }, std::bind(select_whole_word, _1, inner) }, - { { Key::Modifiers::None, 'W' }, std::bind(select_whole_word, _1, inner) }, + { { Key::Modifiers::None, '(' }, std::bind(select_surrounding, _1, CodepointPair{ '(', ')' }, flags) }, + { { Key::Modifiers::None, ')' }, std::bind(select_surrounding, _1, CodepointPair{ '(', ')' }, flags) }, + { { Key::Modifiers::None, 'b' }, std::bind(select_surrounding, _1, CodepointPair{ '(', ')' }, flags) }, + { { Key::Modifiers::None, '{' }, std::bind(select_surrounding, _1, CodepointPair{ '{', '}' }, flags) }, + { { Key::Modifiers::None, '}' }, std::bind(select_surrounding, _1, CodepointPair{ '{', '}' }, flags) }, + { { Key::Modifiers::None, 'B' }, std::bind(select_surrounding, _1, CodepointPair{ '{', '}' }, flags) }, + { { Key::Modifiers::None, '[' }, std::bind(select_surrounding, _1, CodepointPair{ '[', ']' }, flags) }, + { { Key::Modifiers::None, ']' }, std::bind(select_surrounding, _1, CodepointPair{ '[', ']' }, flags) }, + { { Key::Modifiers::None, '<' }, std::bind(select_surrounding, _1, CodepointPair{ '<', '>' }, flags) }, + { { Key::Modifiers::None, '>' }, std::bind(select_surrounding, _1, CodepointPair{ '<', '>' }, flags) }, + { { Key::Modifiers::None, 'w' }, std::bind(select_whole_word, _1, flags & SurroundFlags::Inner) }, + { { Key::Modifiers::None, 'W' }, std::bind(select_whole_word, _1, flags & SurroundFlags::Inner) }, }; auto it = key_to_selector.find(key); @@ -535,8 +535,10 @@ std::unordered_map> keymap = { { Key::Modifiers::None, 'u' }, repeated([](Context& context) { if (not context.editor().undo()) { context.print_status("nothing left to undo"); } }) }, { { Key::Modifiers::None, 'U' }, repeated([](Context& context) { if (not context.editor().redo()) { context.print_status("nothing left to redo"); } }) }, - { { Key::Modifiers::Alt, 'i' }, do_select_object }, - { { Key::Modifiers::Alt, 'a' }, do_select_object }, + { { Key::Modifiers::Alt, 'i' }, do_select_object }, + { { Key::Modifiers::Alt, 'a' }, do_select_object }, + { { Key::Modifiers::None, ']' }, do_select_object }, + { { Key::Modifiers::None, '[' }, do_select_object }, { { Key::Modifiers::Alt, 'w' }, repeated([](Context& context) { context.editor().select(select_to_next_word); }) }, { { Key::Modifiers::Alt, 'e' }, repeated([](Context& context) { context.editor().select(select_to_next_word_end); }) }, -- cgit v1.2.3