From a084f02a2df24a401bd489ba8337913a8932e90a Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 1 Jul 2014 20:10:24 -0700 Subject: [PATCH] Fix a case where the found text would not be selected with find/replace SubsTextEditCtrl::SetTextTo needs to update the selection via the text selection controller or the text selection controller will have an outdated cached state until the UpdateUI event is processed, which soemtimes resulted in it not actually setting the selection when it needed to be. --- src/subs_edit_ctrl.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp index 777f4ad33..9476fe563 100644 --- a/src/subs_edit_ctrl.cpp +++ b/src/subs_edit_ctrl.cpp @@ -37,6 +37,7 @@ #include "include/aegisub/context.h" #include "include/aegisub/spellchecker.h" #include "selection_controller.h" +#include "text_selection_controller.h" #include "thesaurus.h" #include "utils.h" @@ -310,10 +311,18 @@ void SubsTextEditCtrl::SetTextTo(std::string const& text) { auto old_pos = agi::CharacterCount(line_text.begin(), line_text.begin() + insertion_point, 0); line_text.clear(); - SetSelection(0, 0); - SetTextRaw(text.c_str()); - auto pos = agi::IndexOfCharacter(text, old_pos); - SetSelection(pos, pos); + if (context) { + context->textSelectionController->SetSelection(0, 0); + SetTextRaw(text.c_str()); + auto pos = agi::IndexOfCharacter(text, old_pos); + context->textSelectionController->SetSelection(pos, pos); + } + else { + SetSelection(0, 0); + SetTextRaw(text.c_str()); + auto pos = agi::IndexOfCharacter(text, old_pos); + SetSelection(pos, pos); + } SetEvtHandlerEnabled(true); Thaw();