From 44f0fcce07e53d879657439c48853dd993da715e Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 8 Oct 2012 17:02:09 -0700 Subject: [PATCH] Go through TextSelectionController rather than hitting the text edit directly in SubsEditBox --- aegisub/src/subs_edit_box.cpp | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/aegisub/src/subs_edit_box.cpp b/aegisub/src/subs_edit_box.cpp index 122568f3e..369cc7321 100644 --- a/aegisub/src/subs_edit_box.cpp +++ b/aegisub/src/subs_edit_box.cpp @@ -82,17 +82,6 @@ struct field_setter : public std::binary_function { } }; -/// @brief Get the selection from a text edit -/// @return Pair of selection start and end positions -std::pair get_selection(SubsTextEditCtrl *TextEdit) { - int start, end; - TextEdit->GetSelection(&start, &end); - int len = TextEdit->GetText().size(); - return std::make_pair( - mid(0, TextEdit->GetReverseUnicodePosition(start), len), - mid(0, TextEdit->GetReverseUnicodePosition(end), len)); -} - /// @brief Get the value of a tag at a specified position in a line /// @param line Line to get the value from /// @param blockn Block number in the line @@ -611,8 +600,9 @@ void SubsEditBox::SetTag(wxString tag, wxString value, bool atEnd) { if (line->Blocks.empty()) line->ParseASSTags(); - std::pair sel = get_selection(TextEdit); - int start = atEnd ? sel.second : sel.first; + int sel_start = c->textSelectionController->GetSelectionStart(); + int sel_end = c->textSelectionController->GetSelectionEnd(); + int start = atEnd ? sel_end : sel_start; int blockn = block_at_pos(line->Text, start); AssDialogueBlockPlain *plain = 0; @@ -680,7 +670,7 @@ void SubsEditBox::SetTag(wxString tag, wxString value, bool atEnd) { assert(false); TextEdit->SetTextTo(line->Text); - if (!atEnd) TextEdit->SetSelectionU(sel.first+shift,sel.second+shift); + if (!atEnd) c->textSelectionController->SetSelection(sel_start + shift, sel_end + shift); TextEdit->SetFocus(); } @@ -689,13 +679,14 @@ void SubsEditBox::OnFlagButton(bool (AssStyle::*field), const char *tag, wxStrin bool state = style ? style->*field : AssStyle().*field; line->ParseASSTags(); - std::pair sel = get_selection(TextEdit); - int blockn = block_at_pos(line->Text, sel.first); + int sel_start = c->textSelectionController->GetSelectionStart(); + int sel_end = c->textSelectionController->GetSelectionEnd(); + int blockn = block_at_pos(line->Text, sel_start); state = get_value(*line, blockn, state, tag); SetTag(tag, state ? "0" : "1"); - if (sel.first != sel.second) + if (sel_start != sel_end) SetTag(tag, state ? "1" : "0", true); line->ClearBlocks(); @@ -705,7 +696,7 @@ void SubsEditBox::OnFlagButton(bool (AssStyle::*field), const char *tag, wxStrin void SubsEditBox::OnFontButton() { line->ParseASSTags(); - int blockn = block_at_pos(line->Text, get_selection(TextEdit).first); + int blockn = block_at_pos(line->Text, c->textSelectionController->GetInsertionPoint()); AssStyle *style = c->ass->GetStyle(line->Style); AssStyle defStyle; @@ -750,8 +741,9 @@ void SubsEditBox::OnColorButton(AssColor (AssStyle::*field), const char *tag, co line->ParseASSTags(); - std::pair sel = get_selection(TextEdit); - int blockn = block_at_pos(line->Text, sel.first); + int sel_start = c->textSelectionController->GetSelectionStart(); + int sel_end = c->textSelectionController->GetSelectionEnd(); + int blockn = block_at_pos(line->Text, sel_start); color = get_value(*line, blockn, color, colorTag, alt); wxColor newColor = GetColorFromUser(c->parent, color, this); @@ -760,7 +752,7 @@ void SubsEditBox::OnColorButton(AssColor (AssStyle::*field), const char *tag, co if (!newColor.IsOk()) { c->ass->Undo(); - TextEdit->SetSelectionU(sel.first, sel.second); + c->textSelectionController->SetSelection(sel_start, sel_end); } }