From 3c7527c2f78c60505d1a5e98effcc35e4b94525d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 15 Apr 2013 17:01:36 -0700 Subject: [PATCH] Do a better job of picking a new active line after deleting lines Set it to the first line not part of the selection after the selection begins if there are any, and the last line remaining in the file if not (i.e. the last line before the selection). Closes #1595. --- aegisub/src/command/edit.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/aegisub/src/command/edit.cpp b/aegisub/src/command/edit.cpp index b72221671..57f6b22b1 100644 --- a/aegisub/src/command/edit.cpp +++ b/aegisub/src/command/edit.cpp @@ -470,23 +470,22 @@ static void copy_lines(agi::Context *c) { } static void delete_lines(agi::Context *c, wxString const& commit_message) { - AssDialogue *active = c->selectionController->GetActiveLine(); SubtitleSelection sel = c->selectionController->GetSelectedSet(); // Find a line near the active line not being deleted to make the new active line - AssDialogue *new_active = 0; - bool hit_active = false; + AssDialogue *pre_sel = nullptr; + AssDialogue *post_sel = nullptr; + bool hit_selection = false; for (auto diag : c->ass->Line | agi::of_type()) { - if (diag == active) { - hit_active = true; - if (new_active) break; - } - - if (!sel.count(diag)) { - new_active = diag; - if (hit_active) break; + if (sel.count(diag)) + hit_selection = true; + else if (hit_selection && !post_sel) { + post_sel = diag; + break; } + else + pre_sel = diag; } // Delete selected lines @@ -494,6 +493,9 @@ static void delete_lines(agi::Context *c, wxString const& commit_message) { return sel.count(const_cast(static_cast(&e))); }, [](AssEntry *e) { delete e; }); + AssDialogue *new_active = post_sel; + if (!new_active) + new_active = pre_sel; // If we didn't get a new active line then we just deleted all the dialogue // lines, so make a new one if (!new_active) {