diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-02-01 20:54:29 +0000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-02-01 22:53:42 +0000 |
| commit | bc0dfa9e8fe488a1847580b50fa39ad42a987dc2 (patch) | |
| tree | 7255ebd749dc48c41963dbe370ef55d82573c1ed /src/normal.cc | |
| parent | 65bbc19d6fb6c1e9a719d5c2dd5578462a1269b5 (diff) | |
Use <a-'> for backward rotate selection and move rotate content to <a-">
Diffstat (limited to 'src/normal.cc')
| -rw-r--r-- | src/normal.cc | 20 |
1 files changed, 15 insertions, 5 deletions
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<Direction direction> 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<Backward> }, { 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<Forward> }, + { alt('\''), "rotate main selection", rotate_selections<Backward> }, + { alt('"'), "rotate selections content", rotate_selections_content }, { 'q', "replay recorded macro", replay_macro }, { 'Q', "start or end macro recording", start_or_end_macro_recording }, |
