summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-03-25 11:34:38 +1100
committerMaxime Coste <mawww@kakoune.org>2018-03-25 11:39:26 +1100
commitec7f3738ee08fa3c2e095d29dcb61eab37ba434f (patch)
tree117bab642dd25604ab8cbc48930f26eba4a47299
parent683ce8e83b0a4a3ae17567967f68539456a35ffc (diff)
Move rotate selection and rotate selection contents to ) and <a-)>
Backward rotation are supported with (. Fixes #1210
-rw-r--r--doc/keymap4
-rw-r--r--doc/pages/keys.asciidoc13
-rw-r--r--src/normal.cc25
-rw-r--r--test/normal/rotate-content/cmd2
-rw-r--r--test/normal/rotate/cmd2
-rw-r--r--test/normal/trim/cmd2
6 files changed, 30 insertions, 18 deletions
diff --git a/doc/keymap b/doc/keymap
index da2ca472..7ef9fcb5 100644
--- a/doc/keymap
+++ b/doc/keymap
@@ -1,5 +1,5 @@
┌───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┬───────┲━━━━━━━━━━━━━━┓
-│ upper│ cmdout│convtab│ │selpipe│sel all│ │ align│pattern│ │ │ trim│ ┃ ⇤ ┃
+│ upper│ cmdout│convtab│ │selpipe│sel all│ │ align│pattern│ rotate│ rotate│ trim│ ┃ ⇤ ┃
├┄┄CASE┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┨ ┃
│ lower│ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 0 │ │ ┃ ┃
┢━━━━━━━┷━━━┱───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┺━━━┳━━━━━━━━━━┫
@@ -9,7 +9,7 @@
┣━━━━━━━━━━━┻━┱─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┴─┬─────┺━┓ ┃
┃ ⇬ ┃ APPEND│ split│ │ ᵐʳ│ ᵐᵍ│ ᵐˡ│ ᵐ│ ᵐ│ ᵐˡ│cmdline│use reg│ pipe┃ ┃
┃ ┠┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┤ find│ goto │ │ │ │ ├┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┨ ┃
-┃ ┃ append│ select│ delete│ char│ │ ← │ ↓ │ ↑ │ → │ cursor│ rotate│eschook┃ ┃
+┃ ┃ append│ select│ delete│ char│ │ ← │ ↓ │ ↑ │ → │ cursor│ │eschook┃ ┃
┣━━━━━━━━━┳━━━┹───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┬───┴───┲━━━┷━━━━━━━┻━━━━━━━━┫
┃ ┃ indent│ save│ ᵐ│copysel│ ᵛ│ ᵐʷ│ ᵐʳ│ │ dedent│ indent│ ᵐʳ┃ ┃
┃ ┠┄┄┄┄┄┄┄┼┄MARKS┄┤ select├┄┄┄┄┄┄┄┤ view│ prev│ search│ match├┄┄┄┄┄┄┄┼┄┄┄┄┄┄┄┤ search┃ ┃
diff --git a/doc/pages/keys.asciidoc b/doc/pages/keys.asciidoc
index a91fdbc3..76512929 100644
--- a/doc/pages/keys.asciidoc
+++ b/doc/pages/keys.asciidoc
@@ -196,11 +196,11 @@ is a sequence of non whitespace characters
*<c-d>*::
scroll half a page down
-*'*::
- rotate selections (the main selection becomes the next one)
+*)*::
+ rotate main selection (the main selection becomes the next one)
-*<a-'>*::
- rotate selections backwards
+*(*::
+ rotate main selection backward (the main selection becomes the previous one)
*;*::
reduce selections to their cursor
@@ -362,7 +362,7 @@ is a sequence of non whitespace characters
*_*::
trim selections
-*<a-">*::
+*<a-)>*::
rotate selections content, if specified, the count groups selections,
so the following command
@@ -372,6 +372,9 @@ is a sequence of non whitespace characters
rotate (1, 2, 3) and (3, 4, 6) independently
+*<a-(>*::
+ rotate selections content backward
+
== Goto commands
*g*, *G*::
diff --git a/src/normal.cc b/src/normal.cc
index 5d0659d0..1845c708 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -1365,10 +1365,11 @@ void rotate_selections(Context& context, NormalParams params)
: (index + (num - count % num)) % num);
}
+template<Direction direction>
void rotate_selections_content(Context& context, NormalParams params)
{
- int group = params.count;
- int count = 1;
+ size_t group = params.count;
+ size_t count = 1;
auto strings = context.selections_content();
if (group == 0 or group > (int)strings.size())
group = (int)strings.size();
@@ -1376,13 +1377,20 @@ void rotate_selections_content(Context& context, NormalParams params)
for (auto it = strings.begin(); it != strings.end(); )
{
auto end = std::min(strings.end(), it + group);
- std::rotate(it, end-count, end);
+ if (direction == Direction::Forward)
+ std::rotate(it, end-count, end);
+ else
+ std::rotate(it, it+count, end);
it = end;
}
auto& selections = context.selections();
selections.insert(strings, InsertMode::Replace);
- selections.set_main_index((selections.main_index() + count) %
- selections.size());
+ const size_t index = selections.main_index();
+ const size_t index_in_group = index % group;
+ selections.set_main_index(index - index_in_group +
+ (direction == Forward) ?
+ (index_in_group + count) % group
+ : (index_in_group + group - count % group) % group);
}
enum class SelectFlags
@@ -2182,9 +2190,10 @@ static const HashMap<Key, NormalCmd, MemoryDomain::Undefined, KeymapBackend> key
{ {ctrl('o')}, {"jump backward in jump list", jump<Backward>} },
{ {ctrl('s')}, {"push current selections in jump list", push_selections} },
- { {'\''}, {"rotate main selection forward", rotate_selections<Forward>} },
- { {alt('\'')}, {"rotate main selection backward", rotate_selections<Backward>} },
- { {alt('"')}, {"rotate selections content", rotate_selections_content} },
+ { {')'}, {"rotate main selection forward", rotate_selections<Forward>} },
+ { {'('}, {"rotate main selection backward", rotate_selections<Backward>} },
+ { {alt(')')}, {"rotate selections content forward", rotate_selections_content<Forward>} },
+ { {alt('(')}, {"rotate selections content backward", rotate_selections_content<Backward>} },
{ {'q'}, {"replay recorded macro", replay_macro} },
{ {'Q'}, {"start or end macro recording", start_or_end_macro_recording} },
diff --git a/test/normal/rotate-content/cmd b/test/normal/rotate-content/cmd
index 164896b5..1f373d4f 100644
--- a/test/normal/rotate-content/cmd
+++ b/test/normal/rotate-content/cmd
@@ -1 +1 @@
-<a-">
+<a-)>
diff --git a/test/normal/rotate/cmd b/test/normal/rotate/cmd
index a729d2a8..90f0818a 100644
--- a/test/normal/rotate/cmd
+++ b/test/normal/rotate/cmd
@@ -1 +1 @@
-'<a-space>
+)<a-space>
diff --git a/test/normal/trim/cmd b/test/normal/trim/cmd
index d7c8655d..0bd796f5 100644
--- a/test/normal/trim/cmd
+++ b/test/normal/trim/cmd
@@ -1 +1 @@
-%<a-s>_<a-">
+%<a-s>_<a-)>