From 9439d2802893b35594acc94329f57fe16a128e54 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 4 Jul 2014 19:05:00 +0100 Subject: [PATCH] More consistent and behaviour and without count now remove all except/keep main selection. Without reducing main selection to cursor. Reduce to cursor is moved to ';' and flip selections to --- src/normal.cc | 9 +++++---- src/selectors.hh | 21 ++++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 4af47ada7..54348a9bc 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1295,10 +1295,11 @@ KeyMap keymap = { ':', command }, { '|', pipe }, { alt('|'), pipe }, - { ' ', [](Context& context, int count) { if (count == 0) clear_selections(context.selections()); - else keep_selection(context.selections(), count-1); } }, - { alt(' '), [](Context& context, int count) { if (count == 0) flip_selections(context.selections()); - else remove_selection(context.selections(), count-1); } }, + { ' ', [](Context& context, int count) { keep_selection(context.selections(), count ? count-1 : context.selections().main_index()); } }, + { alt(' '), [](Context& context, int count) { remove_selection(context.selections(), count ? count-1 : context.selections().main_index()); } }, + { ';', [](Context& context, int count) { clear_selections(context.selections()); } }, + { alt(';'), [](Context& context, int count) { flip_selections(context.selections()); } }, + { 'w', repeated(make_select(select_to_next_word)) }, { 'e', repeated(make_select(select_to_next_word_end)) }, { 'b', repeated(make_select(select_to_previous_word)) }, diff --git a/src/selectors.hh b/src/selectors.hh index 191a15dc9..c4aa42eaf 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -11,12 +11,8 @@ namespace Kakoune inline void clear_selections(SelectionList& selections) { - auto& sel = selections.main(); - auto& pos = sel.cursor(); - sel.anchor() = pos; - selections.avoid_eol(); - - selections = SelectionList{ selections.buffer(), std::move(sel) }; + for (auto& sel : selections) + sel.anchor() = sel.cursor(); } inline void flip_selections(SelectionList& selections) @@ -29,10 +25,7 @@ inline void flip_selections(SelectionList& selections) inline void keep_selection(SelectionList& selections, int index) { if (index < selections.size()) - { - size_t real_index = (index + selections.main_index() + 1) % selections.size(); - selections = SelectionList{ selections.buffer(), std::move(selections[real_index]) }; - } + selections = SelectionList{ selections.buffer(), std::move(selections[index]) }; selections.check_invariant(); } @@ -40,12 +33,10 @@ inline void remove_selection(SelectionList& selections, int index) { if (selections.size() > 1 and index < selections.size()) { - size_t real_index = (index + selections.main_index() + 1) % selections.size(); - selections.remove(real_index); + selections.remove(index); size_t main_index = selections.main_index(); - if (real_index <= main_index) - selections.set_main_index((main_index > 0 ? main_index - : selections.size()) - 1); + if (index < main_index or main_index == selections.size()) + selections.set_main_index(main_index - 1); } selections.check_invariant(); }