From 3e53ebb5d6a5157a28662e41a34f53f11c835417 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 19 Nov 2012 19:03:56 +0100 Subject: [PATCH] alt-space without numeric parameter now flips selections, inverting first and last char --- src/editor.cc | 7 +++++++ src/editor.hh | 1 + src/main.cc | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/editor.cc b/src/editor.cc index 9c6a97c0..d4c6409d 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -158,6 +158,13 @@ void Editor::clear_selections() m_selections.push_back(std::move(sel)); } +void Editor::flip_selections() +{ + check_invariant(); + for (auto& sel : m_selections) + std::swap(sel.selection.first(), sel.selection.last()); +} + void Editor::keep_selection(int index) { check_invariant(); diff --git a/src/editor.hh b/src/editor.hh index 4ee5dfc2..620b51e2 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -59,6 +59,7 @@ public: void move_selections(CharCount move, SelectMode mode = SelectMode::Replace); void clear_selections(); + void flip_selections(); void keep_selection(int index); void remove_selection(int index); void select(const BufferIterator& iterator); diff --git a/src/main.cc b/src/main.cc index fdbebd22..93e7080c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -422,7 +422,7 @@ std::unordered_map> keymap = if (count == 0) context.editor().clear_selections(); else context.editor().keep_selection(count-1); } }, { { Key::Modifiers::Alt, ' ' }, [](Context& context) { int count = context.numeric_param(); - if (count == 0) context.editor().clear_selections(); + if (count == 0) context.editor().flip_selections(); else context.editor().remove_selection(count-1); } }, { { Key::Modifiers::None, 'w' }, repeated([](Context& context) { context.editor().select(select_to_next_word); }) }, { { Key::Modifiers::None, 'e' }, repeated([](Context& context) { context.editor().select(select_to_next_word_end); }) },