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 **:: scroll half a page down -*'*:: - rotate selections (the main selection becomes the next one) +*)*:: + rotate main selection (the main selection becomes the next one) -**:: - 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 -**:: +**:: 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 +**:: + 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 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 { {ctrl('o')}, {"jump backward in jump list", jump} }, { {ctrl('s')}, {"push current selections in jump list", push_selections} }, - { {'\''}, {"rotate main selection forward", rotate_selections} }, - { {alt('\'')}, {"rotate main selection backward", rotate_selections} }, - { {alt('"')}, {"rotate selections content", rotate_selections_content} }, + { {')'}, {"rotate main selection forward", rotate_selections} }, + { {'('}, {"rotate main selection backward", rotate_selections} }, + { {alt(')')}, {"rotate selections content forward", rotate_selections_content} }, + { {alt('(')}, {"rotate selections content backward", rotate_selections_content} }, { {'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 @@ - + 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 @@ -' +) 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 @@ -%_ +%_