Change the selection before committing deletions of lines
For whatever reason this was sometimes being done after the commit, which resulted in a lot of code only working by coincidence when the grid commit handler happened to be the first one to be called.
This commit is contained in:
parent
2f14c395e7
commit
eee4da0642
4 changed files with 8 additions and 15 deletions
|
@ -315,10 +315,10 @@ void AssKaraoke::SplitLines(std::set<AssDialogue*> const& lines, agi::Context *c
|
||||||
|
|
||||||
if (!did_split) return;
|
if (!did_split) return;
|
||||||
|
|
||||||
c->ass->Commit(_("splitting"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
|
|
||||||
|
|
||||||
AssDialogue *new_active = c->selectionController->GetActiveLine();
|
AssDialogue *new_active = c->selectionController->GetActiveLine();
|
||||||
if (!sel.count(c->selectionController->GetActiveLine()))
|
if (!sel.count(c->selectionController->GetActiveLine()))
|
||||||
new_active = *sel.begin();
|
new_active = *sel.begin();
|
||||||
c->selectionController->SetSelectionAndActive(sel, new_active);
|
c->selectionController->SetSelectionAndActive(sel, new_active);
|
||||||
|
|
||||||
|
c->ass->Commit(_("splitting"), AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -320,14 +320,8 @@ void BaseGrid::UpdateMaps(bool preserve_selected_rows) {
|
||||||
SetSelectedSet(new_sel);
|
SetSelectedSet(new_sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force a reannounce of the active line if it hasn't changed, as it isn't
|
|
||||||
// safe to touch the active line while processing a commit event which would
|
|
||||||
// cause this function to be called
|
|
||||||
AssDialogue *line = active_line;
|
|
||||||
active_line = nullptr;
|
|
||||||
|
|
||||||
// The active line may have ceased to exist; pick a new one if so
|
// The active line may have ceased to exist; pick a new one if so
|
||||||
if (line_index_map.size() && line_index_map.find(line) == line_index_map.end()) {
|
if (line_index_map.size() && !line_index_map.count(active_line)) {
|
||||||
if (active_row < (int)index_line_map.size())
|
if (active_row < (int)index_line_map.size())
|
||||||
SetActiveLine(index_line_map[active_row]);
|
SetActiveLine(index_line_map[active_row]);
|
||||||
else if (preserve_selected_rows && !selection.empty())
|
else if (preserve_selected_rows && !selection.empty())
|
||||||
|
@ -335,9 +329,6 @@ void BaseGrid::UpdateMaps(bool preserve_selected_rows) {
|
||||||
else
|
else
|
||||||
SetActiveLine(index_line_map.back());
|
SetActiveLine(index_line_map.back());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
SetActiveLine(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selection.empty() && active_line) {
|
if (selection.empty() && active_line) {
|
||||||
Selection sel;
|
Selection sel;
|
||||||
|
|
|
@ -494,11 +494,11 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) {
|
||||||
c->ass->InsertLine(new_active);
|
c->ass->InsertLine(new_active);
|
||||||
}
|
}
|
||||||
|
|
||||||
c->ass->Commit(commit_message, AssFile::COMMIT_DIAG_ADDREM);
|
|
||||||
|
|
||||||
sel.clear();
|
sel.clear();
|
||||||
sel.insert(new_active);
|
sel.insert(new_active);
|
||||||
c->selectionController->SetSelectionAndActive(sel, 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 {
|
struct edit_line_copy : public validate_sel_nonempty {
|
||||||
|
@ -670,6 +670,7 @@ static void combine_lines(agi::Context *c, void (*combiner)(AssDialogue *, AssDi
|
||||||
sel.clear();
|
sel.clear();
|
||||||
sel.insert(first);
|
sel.insert(first);
|
||||||
c->selectionController->SetSelectionAndActive(sel, first);
|
c->selectionController->SetSelectionAndActive(sel, first);
|
||||||
|
|
||||||
c->ass->Commit(message, AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
|
c->ass->Commit(message, AssFile::COMMIT_DIAG_ADDREM | AssFile::COMMIT_DIAG_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,8 @@ void SubsController::Close() {
|
||||||
redo_stack.clear();
|
redo_stack.clear();
|
||||||
autosaved_commit_id = saved_commit_id = commit_id + 1;
|
autosaved_commit_id = saved_commit_id = commit_id + 1;
|
||||||
filename.clear();
|
filename.clear();
|
||||||
context->ass->Line.clear();
|
AssFile blank;
|
||||||
|
swap(blank.Line, context->ass->Line);
|
||||||
context->ass->LoadDefault();
|
context->ass->LoadDefault();
|
||||||
context->ass->Commit("", AssFile::COMMIT_NEW);
|
context->ass->Commit("", AssFile::COMMIT_NEW);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue