From bc0dfa9e8fe488a1847580b50fa39ad42a987dc2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 1 Feb 2017 20:54:29 +0000 Subject: Use for backward rotate selection and move rotate content to --- src/normal.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/normal.cc') diff --git a/src/normal.cc b/src/normal.cc index 0dd3401c..6a34f6ac 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1159,9 +1159,16 @@ void copy_selections_on_next_lines(Context& context, NormalParams params) selections.sort_and_merge_overlapping(); } +template void rotate_selections(Context& context, NormalParams params) { - context.selections().rotate_main(params.count != 0 ? params.count : 1); + const int count = params.count ? params.count : 1; + auto& selections = context.selections(); + const int index = selections.main_index(); + const int num = selections.size(); + selections.set_main_index((direction == Forward) ? + (index + count) % num + : (index + (num - count % num)) % num); } void rotate_selections_content(Context& context, NormalParams params) @@ -1178,8 +1185,10 @@ void rotate_selections_content(Context& context, NormalParams params) std::rotate(it, end-count, end); it = end; } - context.selections().insert(strings, InsertMode::Replace); - context.selections().rotate_main(count); + auto& selections = context.selections(); + selections.insert(strings, InsertMode::Replace); + selections.set_main_index((selections.main_index() + count) % + selections.size()); } enum class SelectFlags @@ -1846,8 +1855,9 @@ static NormalCmdDesc cmds[] = { ctrl('o'), "jump backward in jump list", jump }, { ctrl('s'), "push current selections in jump list", push_selections }, - { '\'', "rotate main selection", rotate_selections }, - { alt('\''), "rotate selections content", rotate_selections_content }, + { '\'', "rotate main selection", rotate_selections }, + { alt('\''), "rotate main selection", rotate_selections }, + { alt('"'), "rotate selections content", rotate_selections_content }, { 'q', "replay recorded macro", replay_macro }, { 'Q', "start or end macro recording", start_or_end_macro_recording }, -- cgit v1.2.3