Fix crash when rearranging styles in the style manager

Inserting lines already in an intrusive list at a different position
does not work, unlike with unintrusive lists. Instead, swap each item in
to the correct place.
This commit is contained in:
Thomas Goyne 2012-11-21 07:32:04 -08:00
parent 8e10d67d2f
commit 3f840ceec8
1 changed files with 7 additions and 9 deletions

View File

@ -771,16 +771,14 @@ void DialogStyleManager::MoveStyles(bool storage, int type) {
do_move(styleMap, type, first, last, false);
// Replace styles
entryIter next;
int curn = 0;
for (entryIter cur = c->ass->Line.begin(); cur != c->ass->Line.end(); cur = next) {
next = cur;
next++;
if (dynamic_cast<AssStyle*>(&*cur)) {
c->ass->Line.insert(cur, *styleMap[curn]);
c->ass->Line.erase(cur);
curn++;
}
for (auto it = c->ass->Line.begin(); it != c->ass->Line.end(); ++it) {
if (!dynamic_cast<AssStyle*>(&*it)) continue;
auto new_style_at_pos = c->ass->Line.iterator_to(*styleMap[curn]);
EntryList::node_algorithms::swap_nodes(it.pointed_node(), new_style_at_pos.pointed_node());
if (++curn == styleMap.size()) break;
it = new_style_at_pos;
}
c->ass->Commit(_("style move"), AssFile::COMMIT_STYLES);