Fix assertion failure when deleting all lines

Lines need to be deselected before they're deleted, but new lines need
to be committed before they can be selected, so reorder things to
remove -> insert new line if needed -> commit -> update selection -> delete.
This commit is contained in:
Thomas Goyne 2013-12-01 20:17:52 -08:00
parent 11d1348c2c
commit 4c1a8a21b9
2 changed files with 12 additions and 6 deletions

View file

@ -315,10 +315,10 @@ void AssKaraoke::SplitLines(std::set<AssDialogue*> const& lines, agi::Context *c
if (!did_split) return;
c->ass->Commit(_("splitting"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
AssDialogue *new_active = c->selectionController->GetActiveLine();
if (!sel.count(c->selectionController->GetActiveLine()))
new_active = *sel.begin();
c->selectionController->SetSelectionAndActive(sel, new_active);
c->ass->Commit(_("splitting"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
}

View file

@ -503,10 +503,16 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) {
pre_sel = diag;
}
// Delete selected lines
// Remove the selected lines, but defer the deletion until after we select
// different lines. We can't just change the selection first because we may
// need to create a new dialogue line for it, and we can't select dialogue
// lines until after they're committed.
std::vector<std::unique_ptr<AssEntry>> to_delete;
c->ass->Line.remove_and_dispose_if([&sel](AssEntry const& e) {
return sel.count(const_cast<AssDialogue *>(static_cast<const AssDialogue*>(&e)));
}, [](AssEntry *e) { delete e; });
}, [&](AssEntry *e) {
to_delete.emplace_back(e);
});
AssDialogue *new_active = post_sel;
if (!new_active)
@ -518,11 +524,11 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) {
c->ass->InsertLine(new_active);
}
c->ass->Commit(commit_message, AssFile::COMMIT_DIAG_ADDREM);
sel.clear();
sel.insert(new_active);
c->selectionController->SetSelectionAndActive(sel, new_active);
c->ass->Commit(commit_message, AssFile::COMMIT_DIAG_ADDREM);
}
struct edit_line_copy : public validate_sel_nonempty {