From bc0dfa9e8fe488a1847580b50fa39ad42a987dc2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 1 Feb 2017 20:54:29 +0000 Subject: [PATCH] Use for backward rotate selection and move rotate content to --- README.asciidoc | 5 +++-- doc/manpages/keys.asciidoc | 5 ++++- src/normal.cc | 20 +++++++++++++++----- src/selection.hh | 2 -- test/unit/rotate-content/cmd | 2 +- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 16ccd82d..0390a57a 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -371,6 +371,7 @@ Movement * `pagedown`: scroll down * `'`: rotate selections (the main selection becomes the next one) + * ``: rotate selections backwards * `;`: reduce selections to their cursor * ``: flip the selections direction @@ -463,8 +464,8 @@ Changes * ``: convert spaces to tabs in current selections, uses the buffer tabstop option or the count parameter for tabstop. - * ``: rotate selections content, if specified, the count groups - selections, so `3` rotate (1, 2, 3) and (3, 4, 6) + * ``: 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/doc/manpages/keys.asciidoc b/doc/manpages/keys.asciidoc index d197a64a..0c2b61dd 100644 --- a/doc/manpages/keys.asciidoc +++ b/doc/manpages/keys.asciidoc @@ -164,6 +164,9 @@ is a sequence of non whitespace characters *'*:: rotate selections (the main selection becomes the next one) +**:: + 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 -**:: +**:: rotate selections content, if specified, the count groups selections, so the following command diff --git a/src/normal.cc b/src/normal.cc index 0dd3401c..6a34f6ac 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1159,9 +1159,16 @@ void copy_selections_on_next_lines(Context& context, NormalParams params) selections.sort_and_merge_overlapping(); } +template 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 }, { 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 }, + { alt('\''), "rotate main selection", rotate_selections }, + { alt('"'), "rotate selections content", rotate_selections_content }, { 'q', "replay recorded macro", replay_macro }, { 'Q', "start or end macro recording", start_or_end_macro_recording }, diff --git a/src/selection.hh b/src/selection.hh index 7772f72c..2793fd67 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -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); } diff --git a/test/unit/rotate-content/cmd b/test/unit/rotate-content/cmd index 49416e67..164896b5 100644 --- a/test/unit/rotate-content/cmd +++ b/test/unit/rotate-content/cmd @@ -1 +1 @@ - +