1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 17:02:06 +03:00

More consistent <space> and <a-space> behaviour

<space> and <a-space> 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 <a-;>
This commit is contained in:
Maxime Coste 2014-07-04 19:05:00 +01:00
parent 60bf540ee6
commit 9439d28028
2 changed files with 11 additions and 19 deletions

View File

@ -1295,10 +1295,11 @@ KeyMap keymap =
{ ':', command },
{ '|', pipe<InsertMode::Replace> },
{ alt('|'), pipe<InsertMode::Append> },
{ ' ', [](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<SelectMode::Replace>(select_to_next_word<Word>)) },
{ 'e', repeated(make_select<SelectMode::Replace>(select_to_next_word_end<Word>)) },
{ 'b', repeated(make_select<SelectMode::Replace>(select_to_previous_word<Word>)) },

View File

@ -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();
}