From 2c4bc5582acccae9b41f8ff441ffac82f3731aed Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 29 May 2012 11:15:43 +0000 Subject: [PATCH] Alt-Space permits to remove a selection by index --- src/editor.cc | 8 ++++++++ src/editor.hh | 1 + src/main.cc | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/editor.cc b/src/editor.cc index d1253705..c0e9267a 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -136,6 +136,14 @@ void Editor::keep_selection(int index) } } +void Editor::remove_selection(int index) +{ + check_invariant(); + + if (selections().size() > 1 and index < selections().size()) + m_selections.back().erase(m_selections.back().begin() + index); +} + void Editor::select(const BufferIterator& iterator) { m_selections.back().clear(); diff --git a/src/editor.hh b/src/editor.hh index b41e0a81..5b6750d4 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -43,6 +43,7 @@ public: void move_selections(const BufferCoord& offset, bool append = false); void clear_selections(); void keep_selection(int index); + void remove_selection(int index); void select(const BufferIterator& iterator); void select(const Selector& selector, bool append = false); void multi_select(const MultiSelector& selector); diff --git a/src/main.cc b/src/main.cc index 41e4595d..74d39d9b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -388,6 +388,8 @@ std::unordered_map> keymap { { Key::Modifiers::None, '|' }, do_pipe }, { { Key::Modifiers::None, ' ' }, [](Editor& editor, int count) { if (count == 0) editor.clear_selections(); else editor.keep_selection(count-1); } }, + { { Key::Modifiers::Alt, ' ' }, [](Editor& editor, int count) { if (count == 0) editor.clear_selections(); + else editor.remove_selection(count-1); } }, { { Key::Modifiers::None, 'w' }, [](Editor& editor, int count) { do { editor.select(select_to_next_word); } while(--count > 0); } }, { { Key::Modifiers::None, 'e' }, [](Editor& editor, int count) { do { editor.select(select_to_next_word_end); } while(--count > 0); } }, { { Key::Modifiers::None, 'b' }, [](Editor& editor, int count) { do { editor.select(select_to_previous_word); } while(--count > 0); } },