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