Refactor the way main selection is determined after rotating contents
Fixes #2133
This commit is contained in:
parent
52a3e9a84d
commit
667777521b
|
@ -1435,23 +1435,20 @@ void rotate_selections_content(Context& context, NormalParams params)
|
||||||
if (group == 0 or group > (int)strings.size())
|
if (group == 0 or group > (int)strings.size())
|
||||||
group = (int)strings.size();
|
group = (int)strings.size();
|
||||||
count = count % group;
|
count = count % group;
|
||||||
|
auto& selections = context.selections();
|
||||||
|
auto main = strings.begin() + selections.main_index();
|
||||||
for (auto it = strings.begin(); it != strings.end(); )
|
for (auto it = strings.begin(); it != strings.end(); )
|
||||||
{
|
{
|
||||||
auto end = std::min(strings.end(), it + group);
|
auto end = std::min(strings.end(), it + group);
|
||||||
if (direction == Direction::Forward)
|
auto new_beg = (direction == Direction::Forward) ? end - count : it + count;
|
||||||
std::rotate(it, end-count, end);
|
std::rotate(it, new_beg, end);
|
||||||
else
|
|
||||||
std::rotate(it, it+count, end);
|
if (it <= main and main < end)
|
||||||
|
main = main < new_beg ? end - (new_beg - main) : it + (main - new_beg);
|
||||||
it = end;
|
it = end;
|
||||||
}
|
}
|
||||||
auto& selections = context.selections();
|
|
||||||
selections.insert(strings, InsertMode::Replace);
|
selections.insert(strings, InsertMode::Replace);
|
||||||
const size_t index = selections.main_index();
|
selections.set_main_index(main - strings.begin());
|
||||||
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
|
enum class SelectFlags
|
||||||
|
|
1
test/regression/2133-assert-on-rotate-contents/cmd
Normal file
1
test/regression/2133-assert-on-rotate-contents/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
2<a-)>
|
1
test/regression/2133-assert-on-rotate-contents/in
Normal file
1
test/regression/2133-assert-on-rotate-contents/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
%(foo) %(bar) %(baz)
|
1
test/regression/2133-assert-on-rotate-contents/out
Normal file
1
test/regression/2133-assert-on-rotate-contents/out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bar foo baz
|
Loading…
Reference in New Issue
Block a user