From 159e0d049d6844f6b257b8a71c92616202fe92d8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 26 Mar 2014 23:42:10 +0000 Subject: [PATCH] rotate selection content count parameter groups selections the count parameter does not specify the rotation count, but the size of the rotation groups. with 2 for exemple, selection contents will be swapped for each pair (1 and 2, 3 and 4, ...) --- README.asciidoc | 4 +++- src/normal.cc | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 5cadcc0e..b22d1a1b 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -223,7 +223,9 @@ Changes * _alt-@_: convert spaces to tabs in current selections, uses the buffer tabstop option or the count parameter for tabstop. - * _alt-R_: rotate selections content + * _alt-R_: rotate selections content, if specified, the count groups + selections, so +3+ rotate (1, 2, 3) and (3, 4, 6) + independently. Goto Commands ------------- diff --git a/src/normal.cc b/src/normal.cc index d35b9d15..4297e7bb 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -16,6 +16,7 @@ #include "window.hh" #include "user_interface.hh" #include "utf8_iterator.hh" +#include "debug.hh" namespace Kakoune { @@ -924,16 +925,21 @@ void rotate_selections(Context& context, int count) context.selections().rotate_main(count != 0 ? count : 1); } -void rotate_selections_content(Context& context, int count) +void rotate_selections_content(Context& context, int group) { - if (count == 0) - count = 1; + int count = 1; auto strings = context.selections_content(); - count = count % strings.size(); - std::rotate(strings.begin(), strings.end()-count, strings.end()); - context.selections().rotate_main(count); - ScopedEdition edition(context); + if (group == 0 or group > (int)strings.size()) + group = (int)strings.size(); + count = count % group; + for (auto it = strings.begin(); it != strings.end(); ) + { + auto end = std::min(strings.end(), it + group); + std::rotate(it, end-count, end); + it = end; + } insert(context.buffer(), context.selections(), strings); + context.selections().rotate_main(count); } enum class SelectFlags