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, ...)
This commit is contained in:
Maxime Coste 2014-03-26 23:42:10 +00:00
parent b6e268500d
commit 159e0d049d
2 changed files with 16 additions and 8 deletions

View File

@ -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<a-R>+ rotate (1, 2, 3) and (3, 4, 6)
independently.
Goto Commands
-------------

View File

@ -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<InsertMode::Replace>(context.buffer(), context.selections(), strings);
context.selections().rotate_main(count);
}
enum class SelectFlags