forked from mia/Aegisub
Fix shifting contiguous selections downward
Reverse iterators behave differently from regular iterators when swapping (regular iterators continue to point at the same elements, while reverse iterators do not), so instead use regular iterators with a negative step for shifting down.
This commit is contained in:
parent
921d5ed01a
commit
bbd4cbef78
1 changed files with 14 additions and 13 deletions
|
@ -350,18 +350,19 @@ struct grid_tags_simplify : public Command {
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
static bool move_one(T begin, T end, U const& value) {
|
static bool move_one(T begin, T end, U const& to_move, int step) {
|
||||||
size_t move_count = 0;
|
size_t move_count = 0;
|
||||||
T prev = end;
|
auto prev = end;
|
||||||
for (; begin != end; ++begin) {
|
for (auto it = begin; it != end; std::advance(it, step)) {
|
||||||
typename U::key_type cur = dynamic_cast<typename U::key_type>(&*begin);
|
auto cur = dynamic_cast<typename U::key_type>(&*it);
|
||||||
bool in_set = !!value.count(cur);
|
if (!cur) continue;
|
||||||
if (!in_set && cur)
|
|
||||||
prev = begin;
|
if (!to_move.count(cur))
|
||||||
else if (in_set && prev != end) {
|
prev = it;
|
||||||
begin->swap_nodes(*prev);
|
else if (prev != end) {
|
||||||
prev = begin;
|
it->swap_nodes(*prev);
|
||||||
if (++move_count == value.size())
|
prev = it;
|
||||||
|
if (++move_count == to_move.size())
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,7 +383,7 @@ struct grid_move_up : public Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(agi::Context *c) {
|
void operator()(agi::Context *c) {
|
||||||
if (move_one(c->ass->Line.begin(), c->ass->Line.end(), c->selectionController->GetSelectedSet()))
|
if (move_one(c->ass->Line.begin(), c->ass->Line.end(), c->selectionController->GetSelectedSet(), 1))
|
||||||
c->ass->Commit(_("move lines"), AssFile::COMMIT_ORDER);
|
c->ass->Commit(_("move lines"), AssFile::COMMIT_ORDER);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -400,7 +401,7 @@ struct grid_move_down : public Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(agi::Context *c) {
|
void operator()(agi::Context *c) {
|
||||||
if (move_one(c->ass->Line.rbegin(), c->ass->Line.rend(), c->selectionController->GetSelectedSet()))
|
if (move_one(--c->ass->Line.end(), c->ass->Line.begin(), c->selectionController->GetSelectedSet(), -1))
|
||||||
c->ass->Commit(_("move lines"), AssFile::COMMIT_ORDER);
|
c->ass->Commit(_("move lines"), AssFile::COMMIT_ORDER);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue