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:
parent
b6e268500d
commit
159e0d049d
|
@ -223,7 +223,9 @@ Changes
|
||||||
* _alt-@_: convert spaces to tabs in current selections, uses the buffer
|
* _alt-@_: convert spaces to tabs in current selections, uses the buffer
|
||||||
tabstop option or the count parameter for tabstop.
|
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
|
Goto Commands
|
||||||
-------------
|
-------------
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "window.hh"
|
#include "window.hh"
|
||||||
#include "user_interface.hh"
|
#include "user_interface.hh"
|
||||||
#include "utf8_iterator.hh"
|
#include "utf8_iterator.hh"
|
||||||
|
#include "debug.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -924,16 +925,21 @@ void rotate_selections(Context& context, int count)
|
||||||
context.selections().rotate_main(count != 0 ? count : 1);
|
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)
|
int count = 1;
|
||||||
count = 1;
|
|
||||||
auto strings = context.selections_content();
|
auto strings = context.selections_content();
|
||||||
count = count % strings.size();
|
if (group == 0 or group > (int)strings.size())
|
||||||
std::rotate(strings.begin(), strings.end()-count, strings.end());
|
group = (int)strings.size();
|
||||||
context.selections().rotate_main(count);
|
count = count % group;
|
||||||
ScopedEdition edition(context);
|
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);
|
insert<InsertMode::Replace>(context.buffer(), context.selections(), strings);
|
||||||
|
context.selections().rotate_main(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class SelectFlags
|
enum class SelectFlags
|
||||||
|
|
Loading…
Reference in New Issue
Block a user