diff --git a/src/main.cc b/src/main.cc index ce89d0ee..0ec4b97c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -775,7 +775,8 @@ std::unordered_map> keymap { { Key::Modifiers::None, ':' }, [](Window& window, int count) { do_command(); } }, { { Key::Modifiers::None, '|' }, do_pipe }, - { { Key::Modifiers::None, ' ' }, [](Window& window, int count) { window.clear_selections(); } }, + { { Key::Modifiers::None, ' ' }, [](Window& window, int count) { if (count == 0) window.clear_selections(); + else window.keep_selection(count-1); } }, { { Key::Modifiers::None, 'w' }, [](Window& window, int count) { do { window.select(select_to_next_word); } while(--count > 0); } }, { { Key::Modifiers::None, 'e' }, [](Window& window, int count) { do { window.select(select_to_next_word_end); } while(--count > 0); } }, { { Key::Modifiers::None, 'b' }, [](Window& window, int count) { do { window.select(select_to_previous_word); } while(--count > 0); } }, diff --git a/src/window.cc b/src/window.cc index fb294dd7..2af9564c 100644 --- a/src/window.cc +++ b/src/window.cc @@ -239,6 +239,18 @@ void Window::clear_selections() selections().push_back(std::move(sel)); } +void Window::keep_selection(int index) +{ + check_invariant(); + + if (index < selections().size()) + { + Selection sel = selections()[index]; + selections().clear(); + selections().push_back(std::move(sel)); + } +} + void Window::select(const Selector& selector, bool append) { check_invariant(); diff --git a/src/window.hh b/src/window.hh index c85687bb..e8fcc9e5 100644 --- a/src/window.hh +++ b/src/window.hh @@ -73,6 +73,7 @@ public: void move_cursor_to(const BufferIterator& iterator); void clear_selections(); + void keep_selection(int index); void select(const Selector& selector, bool append = false); void multi_select(const MultiSelector& selector); BufferString selection_content() const;