Use <a-'> for backward rotate selection and move rotate content to <a-">

This commit is contained in:
Maxime Coste 2017-02-01 20:54:29 +00:00
parent 65bbc19d6f
commit bc0dfa9e8f
5 changed files with 23 additions and 11 deletions

View File

@ -371,6 +371,7 @@ Movement
* `pagedown`: scroll down
* `'`: rotate selections (the main selection becomes the next one)
* `<a-'>`: rotate selections backwards
* `;`: reduce selections to their cursor
* `<a-;>`: flip the selections direction
@ -463,8 +464,8 @@ Changes
* `<a-@>`: convert spaces to tabs in current selections, uses the buffer
tabstop option or the count parameter for tabstop.
* `<a-'>`: rotate selections content, if specified, the count groups
selections, so `3<a-'>` rotate (1, 2, 3) and (3, 4, 6)
* `<a-">`: rotate selections content, if specified, the count groups
selections, so `3<a-">` rotate (1, 2, 3) and (3, 4, 6)
independently.
Goto Commands

View File

@ -164,6 +164,9 @@ is a sequence of non whitespace characters
*'*::
rotate selections (the main selection becomes the next one)
*<a-'>*::
rotate selections backwards
*;*::
reduce selections to their cursor
@ -303,7 +306,7 @@ Changes
convert spaces to tabs in current selections, uses the buffer tabstop
option or the count parameter for tabstop
*<a-'>*::
*<a-">*::
rotate selections content, if specified, the count groups selections,
so the following command

View File

@ -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 },

View File

@ -97,8 +97,6 @@ struct SelectionList
size_t main_index() const { return m_main; }
void set_main_index(size_t main) { kak_assert(main < size()); m_main = main; }
void rotate_main(int count) { m_main = (m_main + count) % size(); }
void avoid_eol();
void push_back(const Selection& sel) { m_selections.push_back(sel); }

View File

@ -1 +1 @@
<a-'>
<a-">